2019-07-02 13:30:06

by Yue Haibing

[permalink] [raw]
Subject: [PATCH bpf-next] bpf: cgroup: Fix build error without CONFIG_NET

If CONFIG_NET is not set, gcc building fails:

kernel/bpf/cgroup.o: In function `cg_sockopt_func_proto':
cgroup.c:(.text+0x237e): undefined reference to `bpf_sk_storage_get_proto'
cgroup.c:(.text+0x2394): undefined reference to `bpf_sk_storage_delete_proto'
kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_getsockopt':
(.text+0x2a1f): undefined reference to `lock_sock_nested'
(.text+0x2ca2): undefined reference to `release_sock'
kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_setsockopt':
(.text+0x3006): undefined reference to `lock_sock_nested'
(.text+0x32bb): undefined reference to `release_sock'

Add CONFIG_NET dependency to fix this.

Reported-by: Hulk Robot <[email protected]>
Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
Signed-off-by: YueHaibing <[email protected]>
---
init/Kconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/init/Kconfig b/init/Kconfig
index e2e51b5..341cf2a 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -998,6 +998,7 @@ config CGROUP_PERF
config CGROUP_BPF
bool "Support for eBPF programs attached to cgroups"
depends on BPF_SYSCALL
+ depends on NET
select SOCK_CGROUP_DATA
help
Allow attaching eBPF programs to a cgroup using the bpf(2)
--
2.7.4



2019-07-02 15:53:55

by Stanislav Fomichev

[permalink] [raw]
Subject: Re: [PATCH bpf-next] bpf: cgroup: Fix build error without CONFIG_NET

On 07/02, YueHaibing wrote:
> If CONFIG_NET is not set, gcc building fails:
>
> kernel/bpf/cgroup.o: In function `cg_sockopt_func_proto':
> cgroup.c:(.text+0x237e): undefined reference to `bpf_sk_storage_get_proto'
> cgroup.c:(.text+0x2394): undefined reference to `bpf_sk_storage_delete_proto'
> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_getsockopt':
> (.text+0x2a1f): undefined reference to `lock_sock_nested'
> (.text+0x2ca2): undefined reference to `release_sock'
> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_setsockopt':
> (.text+0x3006): undefined reference to `lock_sock_nested'
> (.text+0x32bb): undefined reference to `release_sock'
>
> Add CONFIG_NET dependency to fix this.
Can you share the config? Do I understand correctly that you have
CONFIG_NET=n and CONFIG_BPF=y? What parts of BPF do you expect to
work in this case?

Less invasive fix would be something along the lines:

diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index 76fa0076f20d..0a00eaca6fae 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -939,6 +939,7 @@ int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,
}
EXPORT_SYMBOL(__cgroup_bpf_run_filter_sysctl);

+#ifdef CONFIG_NET
static bool __cgroup_bpf_prog_array_is_empty(struct cgroup *cgrp,
enum bpf_attach_type attach_type)
{
@@ -1120,6 +1121,7 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level,
return ret;
}
EXPORT_SYMBOL(__cgroup_bpf_run_filter_getsockopt);
+#endif

static ssize_t sysctl_cpy_dir(const struct ctl_dir *dir, char **bufp,
size_t *lenp)
@@ -1386,10 +1388,12 @@ static const struct bpf_func_proto *
cg_sockopt_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
{
switch (func_id) {
+#ifdef CONFIG_NET
case BPF_FUNC_sk_storage_get:
return &bpf_sk_storage_get_proto;
case BPF_FUNC_sk_storage_delete:
return &bpf_sk_storage_delete_proto;
+#endif
#ifdef CONFIG_INET
case BPF_FUNC_tcp_sock:
return &bpf_tcp_sock_proto;

> Reported-by: Hulk Robot <[email protected]>
> Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
> Signed-off-by: YueHaibing <[email protected]>
> ---
> init/Kconfig | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/init/Kconfig b/init/Kconfig
> index e2e51b5..341cf2a 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -998,6 +998,7 @@ config CGROUP_PERF
> config CGROUP_BPF
> bool "Support for eBPF programs attached to cgroups"
> depends on BPF_SYSCALL
> + depends on NET
> select SOCK_CGROUP_DATA
> help
> Allow attaching eBPF programs to a cgroup using the bpf(2)
> --
> 2.7.4
>
>

2019-07-02 16:04:10

by Yonghong Song

[permalink] [raw]
Subject: Re: [PATCH bpf-next] bpf: cgroup: Fix build error without CONFIG_NET



On 7/2/19 6:29 AM, YueHaibing wrote:
> If CONFIG_NET is not set, gcc building fails:
>
> kernel/bpf/cgroup.o: In function `cg_sockopt_func_proto':
> cgroup.c:(.text+0x237e): undefined reference to `bpf_sk_storage_get_proto'
> cgroup.c:(.text+0x2394): undefined reference to `bpf_sk_storage_delete_proto'
> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_getsockopt':
> (.text+0x2a1f): undefined reference to `lock_sock_nested'
> (.text+0x2ca2): undefined reference to `release_sock'
> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_setsockopt':
> (.text+0x3006): undefined reference to `lock_sock_nested'
> (.text+0x32bb): undefined reference to `release_sock'
>
> Add CONFIG_NET dependency to fix this.
>
> Reported-by: Hulk Robot <[email protected]>
> Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
> Signed-off-by: YueHaibing <[email protected]>
> ---
> init/Kconfig | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/init/Kconfig b/init/Kconfig
> index e2e51b5..341cf2a 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -998,6 +998,7 @@ config CGROUP_PERF
> config CGROUP_BPF
> bool "Support for eBPF programs attached to cgroups"
> depends on BPF_SYSCALL
> + depends on NET
> select SOCK_CGROUP_DATA
> help
> Allow attaching eBPF programs to a cgroup using the bpf(2)


Adding CGROUP_BPF depending on CONFIG_NET is not a good idea.
There should be really independent.

How about the following change?

-bash-4.4$ git diff
diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index 76fa0076f20d..0a00eaca6fae 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -939,6 +939,7 @@ int __cgroup_bpf_run_filter_sysctl(struct
ctl_table_header *head,
}
EXPORT_SYMBOL(__cgroup_bpf_run_filter_sysctl);

+#ifdef CONFIG_NET
static bool __cgroup_bpf_prog_array_is_empty(struct cgroup *cgrp,
enum bpf_attach_type
attach_type)
{
@@ -1120,6 +1121,7 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock
*sk, int level,
return ret;
}
EXPORT_SYMBOL(__cgroup_bpf_run_filter_getsockopt);
+#endif

static ssize_t sysctl_cpy_dir(const struct ctl_dir *dir, char **bufp,
size_t *lenp)
@@ -1386,10 +1388,12 @@ static const struct bpf_func_proto *
cg_sockopt_func_proto(enum bpf_func_id func_id, const struct bpf_prog
*prog)
{
switch (func_id) {
+#ifdef CONFIG_NET
case BPF_FUNC_sk_storage_get:
return &bpf_sk_storage_get_proto;
case BPF_FUNC_sk_storage_delete:
return &bpf_sk_storage_delete_proto;
+#endif
#ifdef CONFIG_INET
case BPF_FUNC_tcp_sock:
return &bpf_tcp_sock_proto;

Stanislav, you introduced getsockopt and setsockopt hooks which
have this compilation issues if CONFIG_NET=n.
What do you think for the above change?

2019-07-02 16:08:21

by Yonghong Song

[permalink] [raw]
Subject: Re: [PATCH bpf-next] bpf: cgroup: Fix build error without CONFIG_NET



On 7/2/19 8:53 AM, Stanislav Fomichev wrote:
> On 07/02, YueHaibing wrote:
>> If CONFIG_NET is not set, gcc building fails:
>>
>> kernel/bpf/cgroup.o: In function `cg_sockopt_func_proto':
>> cgroup.c:(.text+0x237e): undefined reference to `bpf_sk_storage_get_proto'
>> cgroup.c:(.text+0x2394): undefined reference to `bpf_sk_storage_delete_proto'
>> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_getsockopt':
>> (.text+0x2a1f): undefined reference to `lock_sock_nested'
>> (.text+0x2ca2): undefined reference to `release_sock'
>> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_setsockopt':
>> (.text+0x3006): undefined reference to `lock_sock_nested'
>> (.text+0x32bb): undefined reference to `release_sock'
>>
>> Add CONFIG_NET dependency to fix this.
> Can you share the config? Do I understand correctly that you have
> CONFIG_NET=n and CONFIG_BPF=y? What parts of BPF do you expect to
> work in this case?
>
> Less invasive fix would be something along the lines:
>
> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
> index 76fa0076f20d..0a00eaca6fae 100644
> --- a/kernel/bpf/cgroup.c
> +++ b/kernel/bpf/cgroup.c
> @@ -939,6 +939,7 @@ int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,
> }
> EXPORT_SYMBOL(__cgroup_bpf_run_filter_sysctl);
>
> +#ifdef CONFIG_NET
> static bool __cgroup_bpf_prog_array_is_empty(struct cgroup *cgrp,
> enum bpf_attach_type attach_type)
> {
> @@ -1120,6 +1121,7 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level,
> return ret;
> }
> EXPORT_SYMBOL(__cgroup_bpf_run_filter_getsockopt);
> +#endif
>
> static ssize_t sysctl_cpy_dir(const struct ctl_dir *dir, char **bufp,
> size_t *lenp)
> @@ -1386,10 +1388,12 @@ static const struct bpf_func_proto *
> cg_sockopt_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
> {
> switch (func_id) {
> +#ifdef CONFIG_NET
> case BPF_FUNC_sk_storage_get:
> return &bpf_sk_storage_get_proto;
> case BPF_FUNC_sk_storage_delete:
> return &bpf_sk_storage_delete_proto;
> +#endif
> #ifdef CONFIG_INET
> case BPF_FUNC_tcp_sock:
> return &bpf_tcp_sock_proto;

Ah. Just send another email without checking inbox.
Looks like the above change is preferred.
YueHaibing, could you make change and resubmit your patch?

>
>> Reported-by: Hulk Robot <[email protected]>
>> Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
>> Signed-off-by: YueHaibing <[email protected]>
>> ---
>> init/Kconfig | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/init/Kconfig b/init/Kconfig
>> index e2e51b5..341cf2a 100644
>> --- a/init/Kconfig
>> +++ b/init/Kconfig
>> @@ -998,6 +998,7 @@ config CGROUP_PERF
>> config CGROUP_BPF
>> bool "Support for eBPF programs attached to cgroups"
>> depends on BPF_SYSCALL
>> + depends on NET
>> select SOCK_CGROUP_DATA
>> help
>> Allow attaching eBPF programs to a cgroup using the bpf(2)
>> --
>> 2.7.4
>>
>>

2019-07-03 03:27:13

by Yue Haibing

[permalink] [raw]
Subject: Re: [PATCH bpf-next] bpf: cgroup: Fix build error without CONFIG_NET

On 2019/7/3 0:04, Yonghong Song wrote:
>
>
> On 7/2/19 8:53 AM, Stanislav Fomichev wrote:
>> On 07/02, YueHaibing wrote:
>>> If CONFIG_NET is not set, gcc building fails:
>>>
>>> kernel/bpf/cgroup.o: In function `cg_sockopt_func_proto':
>>> cgroup.c:(.text+0x237e): undefined reference to `bpf_sk_storage_get_proto'
>>> cgroup.c:(.text+0x2394): undefined reference to `bpf_sk_storage_delete_proto'
>>> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_getsockopt':
>>> (.text+0x2a1f): undefined reference to `lock_sock_nested'
>>> (.text+0x2ca2): undefined reference to `release_sock'
>>> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_setsockopt':
>>> (.text+0x3006): undefined reference to `lock_sock_nested'
>>> (.text+0x32bb): undefined reference to `release_sock'
>>>
>>> Add CONFIG_NET dependency to fix this.
>> Can you share the config? Do I understand correctly that you have
>> CONFIG_NET=n and CONFIG_BPF=y? What parts of BPF do you expect to
>> work in this case?
>>
>> Less invasive fix would be something along the lines:
>>
>> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
>> index 76fa0076f20d..0a00eaca6fae 100644
>> --- a/kernel/bpf/cgroup.c
>> +++ b/kernel/bpf/cgroup.c
>> @@ -939,6 +939,7 @@ int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,
>> }
>> EXPORT_SYMBOL(__cgroup_bpf_run_filter_sysctl);
>>
>> +#ifdef CONFIG_NET
>> static bool __cgroup_bpf_prog_array_is_empty(struct cgroup *cgrp,
>> enum bpf_attach_type attach_type)
>> {
>> @@ -1120,6 +1121,7 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level,
>> return ret;
>> }
>> EXPORT_SYMBOL(__cgroup_bpf_run_filter_getsockopt);
>> +#endif
>>
>> static ssize_t sysctl_cpy_dir(const struct ctl_dir *dir, char **bufp,
>> size_t *lenp)
>> @@ -1386,10 +1388,12 @@ static const struct bpf_func_proto *
>> cg_sockopt_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
>> {
>> switch (func_id) {
>> +#ifdef CONFIG_NET
>> case BPF_FUNC_sk_storage_get:
>> return &bpf_sk_storage_get_proto;
>> case BPF_FUNC_sk_storage_delete:
>> return &bpf_sk_storage_delete_proto;
>> +#endif
>> #ifdef CONFIG_INET
>> case BPF_FUNC_tcp_sock:
>> return &bpf_tcp_sock_proto;
>
> Ah. Just send another email without checking inbox.
> Looks like the above change is preferred.
> YueHaibing, could you make change and resubmit your patch?

Sure, I will test and resubmit it.

>
>>
>>> Reported-by: Hulk Robot <[email protected]>
>>> Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
>>> Signed-off-by: YueHaibing <[email protected]>
>>> ---
>>> init/Kconfig | 1 +
>>> 1 file changed, 1 insertion(+)
>>>
>>> diff --git a/init/Kconfig b/init/Kconfig
>>> index e2e51b5..341cf2a 100644
>>> --- a/init/Kconfig
>>> +++ b/init/Kconfig
>>> @@ -998,6 +998,7 @@ config CGROUP_PERF
>>> config CGROUP_BPF
>>> bool "Support for eBPF programs attached to cgroups"
>>> depends on BPF_SYSCALL
>>> + depends on NET
>>> select SOCK_CGROUP_DATA
>>> help
>>> Allow attaching eBPF programs to a cgroup using the bpf(2)
>>> --
>>> 2.7.4
>>>
>>>

2019-07-03 08:02:07

by Yue Haibing

[permalink] [raw]
Subject: Re: [PATCH bpf-next] bpf: cgroup: Fix build error without CONFIG_NET

On 2019/7/2 23:53, Stanislav Fomichev wrote:
> On 07/02, YueHaibing wrote:
>> If CONFIG_NET is not set, gcc building fails:
>>
>> kernel/bpf/cgroup.o: In function `cg_sockopt_func_proto':
>> cgroup.c:(.text+0x237e): undefined reference to `bpf_sk_storage_get_proto'
>> cgroup.c:(.text+0x2394): undefined reference to `bpf_sk_storage_delete_proto'
>> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_getsockopt':
>> (.text+0x2a1f): undefined reference to `lock_sock_nested'
>> (.text+0x2ca2): undefined reference to `release_sock'
>> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_setsockopt':
>> (.text+0x3006): undefined reference to `lock_sock_nested'
>> (.text+0x32bb): undefined reference to `release_sock'
>>
>> Add CONFIG_NET dependency to fix this.
> Can you share the config? Do I understand correctly that you have
> CONFIG_NET=n and CONFIG_BPF=y? What parts of BPF do you expect to
> work in this case?

Yes, I get this error while doing randconfig building,
it set CONFIG_CGROUP_BPF=y and CONFIG_NET=n

the config file attached.

>
> Less invasive fix would be something along the lines:
>
> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
> index 76fa0076f20d..0a00eaca6fae 100644
> --- a/kernel/bpf/cgroup.c
> +++ b/kernel/bpf/cgroup.c
> @@ -939,6 +939,7 @@ int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,
> }
> EXPORT_SYMBOL(__cgroup_bpf_run_filter_sysctl);
>
> +#ifdef CONFIG_NET
> static bool __cgroup_bpf_prog_array_is_empty(struct cgroup *cgrp,
> enum bpf_attach_type attach_type)
> {
> @@ -1120,6 +1121,7 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level,
> return ret;
> }
> EXPORT_SYMBOL(__cgroup_bpf_run_filter_getsockopt);
> +#endif
>
> static ssize_t sysctl_cpy_dir(const struct ctl_dir *dir, char **bufp,
> size_t *lenp)
> @@ -1386,10 +1388,12 @@ static const struct bpf_func_proto *
> cg_sockopt_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
> {
> switch (func_id) {
> +#ifdef CONFIG_NET
> case BPF_FUNC_sk_storage_get:
> return &bpf_sk_storage_get_proto;
> case BPF_FUNC_sk_storage_delete:
> return &bpf_sk_storage_delete_proto;
> +#endif
> #ifdef CONFIG_INET
> case BPF_FUNC_tcp_sock:
> return &bpf_tcp_sock_proto;
>
>> Reported-by: Hulk Robot <[email protected]>
>> Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
>> Signed-off-by: YueHaibing <[email protected]>
>> ---
>> init/Kconfig | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/init/Kconfig b/init/Kconfig
>> index e2e51b5..341cf2a 100644
>> --- a/init/Kconfig
>> +++ b/init/Kconfig
>> @@ -998,6 +998,7 @@ config CGROUP_PERF
>> config CGROUP_BPF
>> bool "Support for eBPF programs attached to cgroups"
>> depends on BPF_SYSCALL
>> + depends on NET
>> select SOCK_CGROUP_DATA
>> help
>> Allow attaching eBPF programs to a cgroup using the bpf(2)
>> --
>> 2.7.4
>>
>>
>
> .
>


Attachments:
randconfig.txt (94.73 kB)

2019-07-03 08:29:39

by Yue Haibing

[permalink] [raw]
Subject: [PATCH v2 bpf-next] bpf: cgroup: Fix build error without CONFIG_NET

If CONFIG_NET is not set and CONFIG_CGROUP_BPF=y,
gcc building fails:

kernel/bpf/cgroup.o: In function `cg_sockopt_func_proto':
cgroup.c:(.text+0x237e): undefined reference to `bpf_sk_storage_get_proto'
cgroup.c:(.text+0x2394): undefined reference to `bpf_sk_storage_delete_proto'
kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_getsockopt':
(.text+0x2a1f): undefined reference to `lock_sock_nested'
(.text+0x2ca2): undefined reference to `release_sock'
kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_setsockopt':
(.text+0x3006): undefined reference to `lock_sock_nested'
(.text+0x32bb): undefined reference to `release_sock'

Reported-by: Hulk Robot <[email protected]>
Suggested-by: Stanislav Fomichev <[email protected]>
Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
Signed-off-by: YueHaibing <[email protected]>
---
v2: use ifdef macro
---
kernel/bpf/cgroup.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index 76fa007..0a00eac 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -939,6 +939,7 @@ int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,
}
EXPORT_SYMBOL(__cgroup_bpf_run_filter_sysctl);

+#ifdef CONFIG_NET
static bool __cgroup_bpf_prog_array_is_empty(struct cgroup *cgrp,
enum bpf_attach_type attach_type)
{
@@ -1120,6 +1121,7 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level,
return ret;
}
EXPORT_SYMBOL(__cgroup_bpf_run_filter_getsockopt);
+#endif

static ssize_t sysctl_cpy_dir(const struct ctl_dir *dir, char **bufp,
size_t *lenp)
@@ -1386,10 +1388,12 @@ static const struct bpf_func_proto *
cg_sockopt_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
{
switch (func_id) {
+#ifdef CONFIG_NET
case BPF_FUNC_sk_storage_get:
return &bpf_sk_storage_get_proto;
case BPF_FUNC_sk_storage_delete:
return &bpf_sk_storage_delete_proto;
+#endif
#ifdef CONFIG_INET
case BPF_FUNC_tcp_sock:
return &bpf_tcp_sock_proto;
--
2.7.4


2019-07-03 14:47:14

by Yonghong Song

[permalink] [raw]
Subject: Re: [PATCH v2 bpf-next] bpf: cgroup: Fix build error without CONFIG_NET



On 7/3/19 1:26 AM, YueHaibing wrote:
> If CONFIG_NET is not set and CONFIG_CGROUP_BPF=y,
> gcc building fails:
>
> kernel/bpf/cgroup.o: In function `cg_sockopt_func_proto':
> cgroup.c:(.text+0x237e): undefined reference to `bpf_sk_storage_get_proto'
> cgroup.c:(.text+0x2394): undefined reference to `bpf_sk_storage_delete_proto'
> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_getsockopt':
> (.text+0x2a1f): undefined reference to `lock_sock_nested'
> (.text+0x2ca2): undefined reference to `release_sock'
> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_setsockopt':
> (.text+0x3006): undefined reference to `lock_sock_nested'
> (.text+0x32bb): undefined reference to `release_sock'
>
> Reported-by: Hulk Robot <[email protected]>
> Suggested-by: Stanislav Fomichev <[email protected]>
> Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
> Signed-off-by: YueHaibing <[email protected]>

Acked-by: Yonghong Song <[email protected]>

> ---
> v2: use ifdef macro
> ---
> kernel/bpf/cgroup.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
> index 76fa007..0a00eac 100644
> --- a/kernel/bpf/cgroup.c
> +++ b/kernel/bpf/cgroup.c
> @@ -939,6 +939,7 @@ int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,
> }
> EXPORT_SYMBOL(__cgroup_bpf_run_filter_sysctl);
>
> +#ifdef CONFIG_NET
> static bool __cgroup_bpf_prog_array_is_empty(struct cgroup *cgrp,
> enum bpf_attach_type attach_type)
> {
> @@ -1120,6 +1121,7 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level,
> return ret;
> }
> EXPORT_SYMBOL(__cgroup_bpf_run_filter_getsockopt);
> +#endif
>
> static ssize_t sysctl_cpy_dir(const struct ctl_dir *dir, char **bufp,
> size_t *lenp)
> @@ -1386,10 +1388,12 @@ static const struct bpf_func_proto *
> cg_sockopt_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
> {
> switch (func_id) {
> +#ifdef CONFIG_NET
> case BPF_FUNC_sk_storage_get:
> return &bpf_sk_storage_get_proto;
> case BPF_FUNC_sk_storage_delete:
> return &bpf_sk_storage_delete_proto;
> +#endif
> #ifdef CONFIG_INET
> case BPF_FUNC_tcp_sock:
> return &bpf_tcp_sock_proto;
>

2019-07-08 22:40:43

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH v2 bpf-next] bpf: cgroup: Fix build error without CONFIG_NET

On 07/03/2019 10:26 AM, YueHaibing wrote:
> If CONFIG_NET is not set and CONFIG_CGROUP_BPF=y,
> gcc building fails:
>
> kernel/bpf/cgroup.o: In function `cg_sockopt_func_proto':
> cgroup.c:(.text+0x237e): undefined reference to `bpf_sk_storage_get_proto'
> cgroup.c:(.text+0x2394): undefined reference to `bpf_sk_storage_delete_proto'
> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_getsockopt':
> (.text+0x2a1f): undefined reference to `lock_sock_nested'
> (.text+0x2ca2): undefined reference to `release_sock'
> kernel/bpf/cgroup.o: In function `__cgroup_bpf_run_filter_setsockopt':
> (.text+0x3006): undefined reference to `lock_sock_nested'
> (.text+0x32bb): undefined reference to `release_sock'
>
> Reported-by: Hulk Robot <[email protected]>
> Suggested-by: Stanislav Fomichev <[email protected]>
> Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
> Signed-off-by: YueHaibing <[email protected]>

Applied, thanks!