2017-11-07 18:02:30

by Alexei Starovoitov

[permalink] [raw]
Subject: Re: [RFC PATCH] bpf: Add helpers to read useful task_struct members

On 11/7/17 12:55 AM, Naveen N. Rao wrote:
>> I thought such struct shouldn't change layout.
>> If it is we need to fix include/linux/compiler-clang.h to do that
>> anon struct as well.
>
> We considered that, but it looked to be very dependent on the version of
> gcc used to build the kernel. But, this may be a simpler approach for
> the shorter term.
>

why it would depend on version of gcc?
We just need this, no?

diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
index de179993e039..4e29ab6187cb 100644
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -15,3 +15,6 @@
* with any version that can compile the kernel
*/
#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix),
__COUNTER__)
+
+#define randomized_struct_fields_start struct {
+#define randomized_struct_fields_end };

since offsets are mandated by C standard.

From 1583405923534791846@xxx Tue Nov 07 11:19:21 +0000 2017
X-GM-THRID: 1583027203607239623
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread


2017-11-07 11:19:21

by Naveen N. Rao

[permalink] [raw]
Subject: Re: [RFC PATCH] bpf: Add helpers to read useful task_struct members

Alexei Starovoitov wrote:
> On 11/7/17 12:55 AM, Naveen N. Rao wrote:
>>> I thought such struct shouldn't change layout.
>>> If it is we need to fix include/linux/compiler-clang.h to do that
>>> anon struct as well.
>>
>> We considered that, but it looked to be very dependent on the version of
>> gcc used to build the kernel. But, this may be a simpler approach for
>> the shorter term.
>>
>
> why it would depend on version of gcc?

>From what I can see, randomized_struct_fields_start is defined only for
gcc >= 4.6. For older versions, it does not get mapped to an anonymous
structure. We may not care for older gcc versions, but..

The other issue was that __randomize_layout maps to __designated_init
when randstruct plugin is not enabled, which is in turn an attribute on
gcc >= v5.1, but not otherwise.

> We just need this, no?
>
> diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
> index de179993e039..4e29ab6187cb 100644
> --- a/include/linux/compiler-clang.h
> +++ b/include/linux/compiler-clang.h
> @@ -15,3 +15,6 @@
> * with any version that can compile the kernel
> */
> #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix),
> __COUNTER__)
> +
> +#define randomized_struct_fields_start struct {
> +#define randomized_struct_fields_end };
>
> since offsets are mandated by C standard.

Yes, this is what we're testing with and is probably sufficient for our
purposes.

- Naveen



From 1583383802262978702@xxx Tue Nov 07 05:27:45 +0000 2017
X-GM-THRID: 1583027203607239623
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread