2018-02-23 06:59:48

by Yafang Shao

[permalink] [raw]
Subject: [PATCH bpf-next] bpf: NULL pointer check is not needed in BPF_CGROUP_RUN_PROG_INET_SOCK

sk is already allocated in inet_create/inet6_create, hence when
BPF_CGROUP_RUN_PROG_INET_SOCK is executed sk will never be NULL.

The logic is as bellow,
sk = sk_alloc();
if (!sk)
goto out;
BPF_CGROUP_RUN_PROG_INET_SOCK(sk);

Signed-off-by: Yafang Shao <[email protected]>
---
include/linux/bpf-cgroup.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index a7f16e0..8a45666 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h
@@ -96,7 +96,7 @@ int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor,
#define BPF_CGROUP_RUN_PROG_INET_SOCK(sk) \
({ \
int __ret = 0; \
- if (cgroup_bpf_enabled && sk) { \
+ if (cgroup_bpf_enabled) { \
__ret = __cgroup_bpf_run_filter_sk(sk, \
BPF_CGROUP_INET_SOCK_CREATE); \
} \
--
1.8.3.1



2018-02-23 15:32:07

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH bpf-next] bpf: NULL pointer check is not needed in BPF_CGROUP_RUN_PROG_INET_SOCK

On 02/23/2018 07:58 AM, Yafang Shao wrote:
> sk is already allocated in inet_create/inet6_create, hence when
> BPF_CGROUP_RUN_PROG_INET_SOCK is executed sk will never be NULL.
>
> The logic is as bellow,
> sk = sk_alloc();
> if (!sk)
> goto out;
> BPF_CGROUP_RUN_PROG_INET_SOCK(sk);
>
> Signed-off-by: Yafang Shao <[email protected]>

Agree, applied to bpf-next, thanks Yafang!

2018-02-23 17:47:15

by David Miller

[permalink] [raw]
Subject: Re: [PATCH bpf-next] bpf: NULL pointer check is not needed in BPF_CGROUP_RUN_PROG_INET_SOCK

From: Yafang Shao <[email protected]>
Date: Fri, 23 Feb 2018 14:58:41 +0800

> sk is already allocated in inet_create/inet6_create, hence when
> BPF_CGROUP_RUN_PROG_INET_SOCK is executed sk will never be NULL.
>
> The logic is as bellow,
> sk = sk_alloc();
> if (!sk)
> goto out;
> BPF_CGROUP_RUN_PROG_INET_SOCK(sk);
>
> Signed-off-by: Yafang Shao <[email protected]>

Acked-by: David S. Miller <[email protected]>