diff mbox series

[testsuite] tests/binder: Build only for 4.11 and later kernels

Message ID 20220113020915.13560-1-gongruiqi1@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Ondrej Mosnáček
Headers show
Series [testsuite] tests/binder: Build only for 4.11 and later kernels | expand

Commit Message

GONG, Ruiqi Jan. 13, 2022, 2:09 a.m. UTC
Following compilation errors occur when building the tests with
userspace headers exported from kernel 4.4:

binder_common.c:111:14: error: ‘const struct flat_binder_object’ has no
member named ‘hdr’
   switch (obj->hdr.type) {
              ^
client.c:58:9: error: dereferencing pointer to incomplete type
  if (obj->hdr.type != BINDER_TYPE_FD) {
         ^

It's been checked that member `hdr` of `struct flat_binder_object` and
`struct binder_fd_object` were both introduced by commit feba3900cabb
("binder: Split flat_binder_object") in kernel v4.11-rc1. Fix this
by adding kernel version check at compile time.

Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
---
 tests/Makefile | 2 ++
 1 file changed, 2 insertions(+)

Comments

Ondrej Mosnacek Jan. 31, 2022, 1:47 p.m. UTC | #1
On Thu, Jan 13, 2022 at 2:48 AM GONG, Ruiqi <gongruiqi1@huawei.com> wrote:
> Following compilation errors occur when building the tests with
> userspace headers exported from kernel 4.4:
>
> binder_common.c:111:14: error: ‘const struct flat_binder_object’ has no
> member named ‘hdr’
>    switch (obj->hdr.type) {
>               ^
> client.c:58:9: error: dereferencing pointer to incomplete type
>   if (obj->hdr.type != BINDER_TYPE_FD) {
>          ^
>
> It's been checked that member `hdr` of `struct flat_binder_object` and
> `struct binder_fd_object` were both introduced by commit feba3900cabb
> ("binder: Split flat_binder_object") in kernel v4.11-rc1. Fix this
> by adding kernel version check at compile time.

Sorry for the late reaction... In a corner case, one might be on a
system where the kernel UAPI headers don't match the running kernel
version 100%, so I'd prefer to grep the header for 'struct
binder_fd_object' over a kernel version check here. In this case the
actual ABI is the same before and after the kernel commit, so it makes
sense to only check if we have a <linux/android/binder.h> that we can
compile against.

Something like:

ifeq ($(shell grep -q 'struct binder_fd_object'
$(INCLUDEDIR)/linux/android/binder.h && echo true),true)
...
endif

> Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
>
> ---
>  tests/Makefile | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/tests/Makefile b/tests/Makefile
> index 3f7cae3..22458a7 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -54,8 +54,10 @@ SUBDIRS += prlimit
>  endif
>
>  ifeq ($(shell grep -q binder $(POLDEV)/include/support/all_perms.spt && test -e $(INCLUDEDIR)/linux/android/binder.h && echo true),true)
> +ifneq ($(shell ./kvercmp $$(uname -r) 4.11),-1)
>  SUBDIRS += binder
>  endif
> +endif
>
>  ifeq ($(shell grep -q bpf $(POLDEV)/include/support/all_perms.spt && echo true),true)
>  ifneq ($(shell ./kvercmp $$(uname -r) 4.15),-1)
> --
> 2.17.1
>

--
Ondrej Mosnacek
Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
GONG, Ruiqi Feb. 9, 2022, 6:58 a.m. UTC | #2
On 2022/01/31 21:47, Ondrej Mosnacek wrote:
> On Thu, Jan 13, 2022 at 2:48 AM GONG, Ruiqi <gongruiqi1@huawei.com> wrote:
>> Following compilation errors occur when building the tests with
>> userspace headers exported from kernel 4.4:
>>
>> binder_common.c:111:14: error: ‘const struct flat_binder_object’ has no
>> member named ‘hdr’
>>    switch (obj->hdr.type) {
>>               ^
>> client.c:58:9: error: dereferencing pointer to incomplete type
>>   if (obj->hdr.type != BINDER_TYPE_FD) {
>>          ^
>>
>> It's been checked that member `hdr` of `struct flat_binder_object` and
>> `struct binder_fd_object` were both introduced by commit feba3900cabb
>> ("binder: Split flat_binder_object") in kernel v4.11-rc1. Fix this
>> by adding kernel version check at compile time.
> 
> Sorry for the late reaction... In a corner case, one might be on a
> system where the kernel UAPI headers don't match the running kernel
> version 100%, so I'd prefer to grep the header for 'struct
> binder_fd_object' over a kernel version check here. In this case the
> actual ABI is the same before and after the kernel commit, so it makes
> sense to only check if we have a <linux/android/binder.h> that we can
> compile against.
> 
> Something like:
> 
> ifeq ($(shell grep -q 'struct binder_fd_object'
> $(INCLUDEDIR)/linux/android/binder.h && echo true),true)
> ...
> endif
> 

Just came back to work from the long New Year holiday... Yeah it sounds
good. Checking the kernel header is a better solution indeed to avoid
overkill. I will prepare a new patch for this. Thx.

>> Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
>>
>> ---
>>  tests/Makefile | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/tests/Makefile b/tests/Makefile
>> index 3f7cae3..22458a7 100644
>> --- a/tests/Makefile
>> +++ b/tests/Makefile
>> @@ -54,8 +54,10 @@ SUBDIRS += prlimit
>>  endif
>>
>>  ifeq ($(shell grep -q binder $(POLDEV)/include/support/all_perms.spt && test -e $(INCLUDEDIR)/linux/android/binder.h && echo true),true)
>> +ifneq ($(shell ./kvercmp $$(uname -r) 4.11),-1)
>>  SUBDIRS += binder
>>  endif
>> +endif
>>
>>  ifeq ($(shell grep -q bpf $(POLDEV)/include/support/all_perms.spt && echo true),true)
>>  ifneq ($(shell ./kvercmp $$(uname -r) 4.15),-1)
>> --
>> 2.17.1
>>
> 
> --
> Ondrej Mosnacek
> Software Engineer, Linux Security - SELinux kernel
> Red Hat, Inc.
> 
> .
diff mbox series

Patch

diff --git a/tests/Makefile b/tests/Makefile
index 3f7cae3..22458a7 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -54,8 +54,10 @@  SUBDIRS += prlimit
 endif
 
 ifeq ($(shell grep -q binder $(POLDEV)/include/support/all_perms.spt && test -e $(INCLUDEDIR)/linux/android/binder.h && echo true),true)
+ifneq ($(shell ./kvercmp $$(uname -r) 4.11),-1)
 SUBDIRS += binder
 endif
+endif
 
 ifeq ($(shell grep -q bpf $(POLDEV)/include/support/all_perms.spt && echo true),true)
 ifneq ($(shell ./kvercmp $$(uname -r) 4.15),-1)