tools/capable: Set data to zero before setting fields.
authorFrancis Laniel <flaniel@microsoft.com>
Mon, 11 Oct 2021 15:35:12 +0000 (17:35 +0200)
committeryonghong-song <ys114321@gmail.com>
Tue, 12 Oct 2021 17:32:19 +0000 (10:32 -0700)
This commit ensures data contains all 0 before setting its fields.
So, even if some fields are not set, there should be no problem with unaligned
access.

Signed-off-by: Francis Laniel <flaniel@microsoft.com>
tools/capable.py

index b89f2af9c15653d99e6504c1dfdfe831d4903bdc..acaa43c3cc7119d8bb9a5f12fa61108e1af0b5af 100755 (executable)
@@ -182,7 +182,15 @@ int kprobe__cap_capable(struct pt_regs *ctx, const struct cred *cred,
     }
 
     u32 uid = bpf_get_current_uid_gid();
-    struct data_t data = {.tgid = tgid, .pid = pid, .uid = uid, .cap = cap, .audit = audit, .insetid = insetid};
+
+    struct data_t data = {};
+
+    data.tgid = tgid;
+    data.pid = pid;
+    data.uid = uid;
+    data.cap = cap;
+    data.audit = audit;
+    data.insetid = insetid;
 #ifdef KERNEL_STACKS
     data.kernel_stack_id = stacks.get_stackid(ctx, 0);
 #endif