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: <20230421182054.fisbe6dowoif3eta@dhcp-172-26-102-232.dhcp.thefacebook.com>
Date:   Fri, 21 Apr 2023 11:20:54 -0700
From:   Alexei Starovoitov <alexei.starovoitov@...il.com>
To:     Feng zhou <zhoufeng.zf@...edance.com>
Cc:     martin.lau@...ux.dev, ast@...nel.org, daniel@...earbox.net,
        andrii@...nel.org, song@...nel.org, yhs@...com,
        john.fastabend@...il.com, kpsingh@...nel.org, sdf@...gle.com,
        haoluo@...gle.com, jolsa@...nel.org, davem@...emloft.net,
        edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
        mykolal@...com, shuah@...nel.org, bpf@...r.kernel.org,
        linux-kernel@...r.kernel.org, netdev@...r.kernel.org,
        linux-kselftest@...r.kernel.org, yangzhenze@...edance.com,
        wangdongdong.6@...edance.com
Subject: Re: [PATCH bpf-next v2 1/2] bpf: Add bpf_task_under_cgroup() kfunc

On Fri, Apr 21, 2023 at 05:04:02PM +0800, Feng zhou wrote:
> From: Feng Zhou <zhoufeng.zf@...edance.com>
> 
> Add a kfunc that's similar to the bpf_current_task_under_cgroup.
> The difference is that it is a designated task.
> 
> When hook sched related functions, sometimes it is necessary to
> specify a task instead of the current task.
> 
> Signed-off-by: Feng Zhou <zhoufeng.zf@...edance.com>
> ---
>  kernel/bpf/helpers.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index 00e5fb0682ac..88e3247b5c44 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
> @@ -2142,6 +2142,24 @@ __bpf_kfunc struct cgroup *bpf_cgroup_from_id(u64 cgid)
>  		return NULL;
>  	return cgrp;
>  }
> +
> +/**
> + * bpf_task_under_cgroup - Check whether the task is a given subset of the
> + * cgroup2 hierarchy. The cgroup2 to test is assigned by cgrp.

That doesn't read right.

> + * @cgrp: assigned cgrp.
> + * @task: assigned task.

This is also wrong.
Please copy paste from task_under_cgroup_hierarchy.

> + */
> +__bpf_kfunc int bpf_task_under_cgroup(struct cgroup *cgrp,
> +				      struct task_struct *task)

return type needs to be 'long'. 'int' might have issues.
Also the args should be task, cgrp to match task_under_cgroup_hierarchy.

> +{
> +	if (unlikely(!cgrp))
> +		return -EAGAIN;
> +
> +	if (unlikely(!task))
> +		return -ENOENT;

Please do
if (unlikely(!cgrp || !task))
        return -EINVAL;

> +
> +	return task_under_cgroup_hierarchy(task, cgrp);
> +}
>  #endif /* CONFIG_CGROUPS */
>  
>  /**
> @@ -2341,6 +2359,7 @@ BTF_ID_FLAGS(func, bpf_cgroup_acquire, KF_ACQUIRE | KF_RCU | KF_RET_NULL)
>  BTF_ID_FLAGS(func, bpf_cgroup_release, KF_RELEASE)
>  BTF_ID_FLAGS(func, bpf_cgroup_ancestor, KF_ACQUIRE | KF_RCU | KF_RET_NULL)
>  BTF_ID_FLAGS(func, bpf_cgroup_from_id, KF_ACQUIRE | KF_RET_NULL)
> +BTF_ID_FLAGS(func, bpf_task_under_cgroup, KF_RCU)
>  #endif
>  BTF_ID_FLAGS(func, bpf_task_from_pid, KF_ACQUIRE | KF_RET_NULL)
>  BTF_SET8_END(generic_btf_ids)
> -- 
> 2.20.1
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ