lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 29 Jul 2020 00:09:40 -0700
From:   Yonghong Song <yhs@...com>
To:     Giuliano Procida <gprocida@...gle.com>
CC:     <linux-kernel@...r.kernel.org>
Subject: Re: BTF_KIND_FWD enums



On 7/28/20 1:56 PM, Giuliano Procida wrote:
> Hi.
> 
> Re: https://github.com/torvalds/linux/commit/9d5f9f701b1891466fb3dbb1806ad97716f95cc3
> 
> Both GCC and LLVM support forward-declared (a.k.a. incomplete) enums
> as a language extension -
> https://gcc.gnu.org/onlinedocs/gcc/Incomplete-Enums.html.
> 
> (C++11 has a different notion of incomplete enum type - opaque enum
> declaration - storage size is known but enumerators are not)
> 
> Forward-declared enums feature in various places in kernel code and
> allow the usual things to be done (passing around pointers to such).
> I'm curious as to if and how they are they are handled by BTF and
> whether a further change to btf_type is needed:
> 
> 1. Use BTF_KIND_FWD, with another spare bit to allow up to 4 kinds of
> forward-declaration; or
> 2. use BTF_KIND_ENUM, kind_flag 0 and vlen 0 (as empty enums are
> currently illegal C); or

#2 above is the current way.
-bash-4.4$ cat t.c
enum H;
enum H * func(enum H *arg) { return arg; }
-bash-4.4$ clang -target bpf -S -g -O2 t.c 

-bash-4.4$

The generated BTF enum type:

         .long   1                               # BTF_KIND_ENUM(id = 2)
         .long   100663296                       # 0x6000000
         .long   0

So vlen = 0 here indicates it is a forward declaration.

> 3. use BTF_KIND_ENUM, kind_flag 1 and vlen 0.
> 
> If I had a working pahole -J, I'd test this myself. :-)
> 
> $ cat /tmp/en.c
> enum H;
> enum H * fun(enum H * x) { return x; }
> $ clang -Wall -Wextra -ggdb -c /tmp/en.c
> $ build/pahole -J /tmp/en.o
> Segmentation fault
> $ build/pahole -J /dev/null
> btf_elf__new: cannot get elf header.
> ctf__new: cannot get elf header.
> Segmentation fault

-bash-4.4$ cat t.c
enum H;
enum H * func(enum H *arg) { return arg; }
-bash-4.4$ ~/work/pahole/build/pahole --version
v1.17
-bash-4.4$ clang -Wall -Wextra -ggdb -c t.c 

-bash-4.4$ ~/work/pahole/build/pahole -JV t.o
File t.o:
[1] PTR (anon) type_id=2
[2] ENUM H size=4 vlen=0
[3] INT (anon) size=4 bit_offset=0 nr_bits=32 encoding=(none)
[4] FUNC_PROTO (anon) return=1 args=(1 arg)
[5] FUNC func type_id=4

pahole also generates vlen=0 ENUM type to indicate it is a
forward declaration.

Maybe your pahole is too old?

> 
> My interest here is that I helped add support for incomplete enums to
> libabigail which we're using to monitor kernel ABIs.
> 
> Regards,
> Giuliano.
> 
> (resend due to email address typo)
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ