lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220218095612.52082-3-laoar.shao@gmail.com>
Date:   Fri, 18 Feb 2022 09:56:11 +0000
From:   Yafang Shao <laoar.shao@...il.com>
To:     ast@...nel.org, daniel@...earbox.net, andrii@...nel.org,
        kafai@...com, songliubraving@...com, yhs@...com,
        john.fastabend@...il.com, kpsingh@...nel.org
Cc:     netdev@...r.kernel.org, bpf@...r.kernel.org,
        Yafang Shao <laoar.shao@...il.com>
Subject: [PATCH RFC 2/3] bpf: set attached cgroup name in attach_name

Set the cgroup path when a bpf prog is attached to a cgroup, and unset
it when the bpf prog is detached.

Below is the result after this change,
$ cat progs.debug
  id name             attached
   5 dump_bpf_map     bpf_iter_bpf_map
   7 dump_bpf_prog    bpf_iter_bpf_prog
  17 bpf_sockmap      cgroup:/
  19 bpf_redir_proxy

Signed-off-by: Yafang Shao <laoar.shao@...il.com>
---
 kernel/bpf/cgroup.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index 43eb3501721b..ebd87e54f2d0 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -440,6 +440,7 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,
 	struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
 	struct bpf_cgroup_storage *new_storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
 	enum cgroup_bpf_attach_type atype;
+	char cgrp_path[64] = "cgroup:";
 	struct bpf_prog_list *pl;
 	struct list_head *progs;
 	int err;
@@ -508,6 +509,11 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,
 	else
 		static_branch_inc(&cgroup_bpf_enabled_key[atype]);
 	bpf_cgroup_storages_link(new_storage, cgrp, type);
+
+	cgroup_name(cgrp, cgrp_path + strlen("cgroup:"), 64);
+	cgrp_path[63] = '\0';
+	prog->aux->attach_name = kstrdup(cgrp_path, GFP_KERNEL);
+
 	return 0;
 
 cleanup:
@@ -735,6 +741,8 @@ static int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
 	if (old_prog)
 		bpf_prog_put(old_prog);
 	static_branch_dec(&cgroup_bpf_enabled_key[atype]);
+	kfree(prog->aux->attach_name);
+
 	return 0;
 
 cleanup:
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ