linux-stable/tools/lib
Kees Cook 52a9dab6d8 libsubcmd: Fix use-after-free for realloc(..., 0)
GCC 12 correctly reports a potential use-after-free condition in the
xrealloc helper. Fix the warning by avoiding an implicit "free(ptr)"
when size == 0:

In file included from help.c:12:
In function 'xrealloc',
    inlined from 'add_cmdname' at help.c:24:2: subcmd-util.h:56:23: error: pointer may be used after 'realloc' [-Werror=use-after-free]
   56 |                 ret = realloc(ptr, size);
      |                       ^~~~~~~~~~~~~~~~~~
subcmd-util.h:52:21: note: call to 'realloc' here
   52 |         void *ret = realloc(ptr, size);
      |                     ^~~~~~~~~~~~~~~~~~
subcmd-util.h:58:31: error: pointer may be used after 'realloc' [-Werror=use-after-free]
   58 |                         ret = realloc(ptr, 1);
      |                               ^~~~~~~~~~~~~~~
subcmd-util.h:52:21: note: call to 'realloc' here
   52 |         void *ret = realloc(ptr, size);
      |                     ^~~~~~~~~~~~~~~~~~

Fixes: 2f4ce5ec1d ("perf tools: Finalize subcmd independence")
Reported-by: Valdis Klētnieks <valdis.kletnieks@vt.edu>
Signed-off-by: Kees Kook <keescook@chromium.org>
Tested-by: Valdis Klētnieks <valdis.kletnieks@vt.edu>
Tested-by: Justin M. Forbes <jforbes@fedoraproject.org>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: linux-hardening@vger.kernel.org
Cc: Valdis Klētnieks <valdis.kletnieks@vt.edu>
Link: http://lore.kernel.org/lkml/20220213182443.4037039-1-keescook@chromium.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-02-16 13:49:25 -03:00
..
api tools api fs: Cache cgroupfs mount point 2021-02-17 15:09:08 -03:00
bpf libbpf: Add documentation for bpf_map batch operations 2022-01-06 15:12:42 -08:00
perf libperf: Fix perf_cpu_map__for_each_cpu macro 2022-02-16 13:49:25 -03:00
subcmd libsubcmd: Fix use-after-free for realloc(..., 0) 2022-02-16 13:49:25 -03:00
symbol
traceevent libtraceevent: Add __rel_loc relative location attribute support 2021-12-06 15:37:22 -05:00
argv_split.c
bitmap.c tools lib: Adopt bitmap_intersects() operation from the kernel sources 2021-06-30 15:28:00 -03:00
ctype.c
find_bit.c tools: sync tools/bitmap with mother linux 2022-01-15 08:47:31 -08:00
hweight.c
list_sort.c tools lib: Adopt list_sort() from the kernel sources 2021-10-20 10:30:59 -03:00
rbtree.c
str_error_r.c
string.c
vsprintf.c
zalloc.c