Skip to content

Commit 06cc6e5

Browse files
committed
Daniel Borkmann says: ==================== pull-request: bpf 2021-01-29 1) Fix two copy_{from,to}_user() warn_on_once splats for BPF cgroup getsockopt infra when user space is trying to race against optlen, from Loris Reiff. 2) Fix a missing fput() in BPF inode storage map update helper, from Pan Bian. 3) Fix a build error on unresolved symbols on disabled networking / keys LSM hooks, from Mikko Ylinen. 4) Fix preload BPF prog build when the output directory from make points to a relative path, from Quentin Monnet. * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: bpf, preload: Fix build when $(O) points to a relative path bpf: Drop disabled LSM hooks from the sleepable set bpf, inode_storage: Put file handler if no storage was found bpf, cgroup: Fix problematic bounds check bpf, cgroup: Fix optlen WARN_ON_ONCE toctou ==================== Link: https://lore.kernel.org/r/20210129001556.6648-1-daniel@iogearbox.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 909b447 + 150a273 commit 06cc6e5

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

kernel/bpf/bpf_inode_storage.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,12 @@ static int bpf_fd_inode_storage_update_elem(struct bpf_map *map, void *key,
125125

126126
fd = *(int *)key;
127127
f = fget_raw(fd);
128-
if (!f || !inode_storage_ptr(f->f_inode))
128+
if (!f)
129+
return -EBADF;
130+
if (!inode_storage_ptr(f->f_inode)) {
131+
fput(f);
129132
return -EBADF;
133+
}
130134

131135
sdata = bpf_local_storage_update(f->f_inode,
132136
(struct bpf_local_storage_map *)map,

kernel/bpf/bpf_lsm.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ BTF_ID(func, bpf_lsm_file_ioctl)
149149
BTF_ID(func, bpf_lsm_file_lock)
150150
BTF_ID(func, bpf_lsm_file_open)
151151
BTF_ID(func, bpf_lsm_file_receive)
152+
153+
#ifdef CONFIG_SECURITY_NETWORK
152154
BTF_ID(func, bpf_lsm_inet_conn_established)
155+
#endif /* CONFIG_SECURITY_NETWORK */
156+
153157
BTF_ID(func, bpf_lsm_inode_create)
154158
BTF_ID(func, bpf_lsm_inode_free_security)
155159
BTF_ID(func, bpf_lsm_inode_getattr)
@@ -166,7 +170,11 @@ BTF_ID(func, bpf_lsm_inode_symlink)
166170
BTF_ID(func, bpf_lsm_inode_unlink)
167171
BTF_ID(func, bpf_lsm_kernel_module_request)
168172
BTF_ID(func, bpf_lsm_kernfs_init_security)
173+
174+
#ifdef CONFIG_KEYS
169175
BTF_ID(func, bpf_lsm_key_free)
176+
#endif /* CONFIG_KEYS */
177+
170178
BTF_ID(func, bpf_lsm_mmap_file)
171179
BTF_ID(func, bpf_lsm_netlink_send)
172180
BTF_ID(func, bpf_lsm_path_notify)
@@ -181,6 +189,8 @@ BTF_ID(func, bpf_lsm_sb_show_options)
181189
BTF_ID(func, bpf_lsm_sb_statfs)
182190
BTF_ID(func, bpf_lsm_sb_umount)
183191
BTF_ID(func, bpf_lsm_settime)
192+
193+
#ifdef CONFIG_SECURITY_NETWORK
184194
BTF_ID(func, bpf_lsm_socket_accept)
185195
BTF_ID(func, bpf_lsm_socket_bind)
186196
BTF_ID(func, bpf_lsm_socket_connect)
@@ -195,6 +205,8 @@ BTF_ID(func, bpf_lsm_socket_recvmsg)
195205
BTF_ID(func, bpf_lsm_socket_sendmsg)
196206
BTF_ID(func, bpf_lsm_socket_shutdown)
197207
BTF_ID(func, bpf_lsm_socket_socketpair)
208+
#endif /* CONFIG_SECURITY_NETWORK */
209+
198210
BTF_ID(func, bpf_lsm_syslog)
199211
BTF_ID(func, bpf_lsm_task_alloc)
200212
BTF_ID(func, bpf_lsm_task_getsecid)

kernel/bpf/cgroup.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,11 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level,
14421442
goto out;
14431443
}
14441444

1445+
if (ctx.optlen < 0) {
1446+
ret = -EFAULT;
1447+
goto out;
1448+
}
1449+
14451450
if (copy_from_user(ctx.optval, optval,
14461451
min(ctx.optlen, max_optlen)) != 0) {
14471452
ret = -EFAULT;
@@ -1459,7 +1464,7 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level,
14591464
goto out;
14601465
}
14611466

1462-
if (ctx.optlen > max_optlen) {
1467+
if (ctx.optlen > max_optlen || ctx.optlen < 0) {
14631468
ret = -EFAULT;
14641469
goto out;
14651470
}

kernel/bpf/preload/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ LIBBPF_SRCS = $(srctree)/tools/lib/bpf/
44
LIBBPF_A = $(obj)/libbpf.a
55
LIBBPF_OUT = $(abspath $(obj))
66

7+
# Although not in use by libbpf's Makefile, set $(O) so that the "dummy" test
8+
# in tools/scripts/Makefile.include always succeeds when building the kernel
9+
# with $(O) pointing to a relative path, as in "make O=build bindeb-pkg".
710
$(LIBBPF_A):
8-
$(Q)$(MAKE) -C $(LIBBPF_SRCS) OUTPUT=$(LIBBPF_OUT)/ $(LIBBPF_OUT)/libbpf.a
11+
$(Q)$(MAKE) -C $(LIBBPF_SRCS) O=$(LIBBPF_OUT)/ OUTPUT=$(LIBBPF_OUT)/ $(LIBBPF_OUT)/libbpf.a
912

1013
userccflags += -I $(srctree)/tools/include/ -I $(srctree)/tools/include/uapi \
1114
-I $(srctree)/tools/lib/ -Wno-unused-result

0 commit comments

Comments
 (0)