[PATCH bpf-next v4 4/9] bpf: Validate kdata of a struct_ops before transiting to READY.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



By utilizing this check, we can avoid creating a struct_ops that
cannot be registered afterward. This way, future complications can be
avoided with ease.

Signed-off-by: Kui-Feng Lee <kuifeng@xxxxxxxx>
---
 kernel/bpf/bpf_struct_ops.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
index dcb7a408d4e9..c71c8d73c7ad 100644
--- a/kernel/bpf/bpf_struct_ops.c
+++ b/kernel/bpf/bpf_struct_ops.c
@@ -504,6 +504,11 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
 
 	set_memory_rox((long)st_map->image, 1);
 	if (st_map->map.map_flags & BPF_F_LINK) {
+		if (st_ops->validate) {
+			err = st_ops->validate(kdata);
+			if (err)
+				goto unlock;
+		}
 		/* Let bpf_link handle registration & unregistration.
 		 *
 		 * Pair with smp_load_acquire() during lookup_elem().
-- 
2.34.1





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux