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]
Date: Thu, 15 Jun 2023 22:46:57 -0700
From: Kui-Feng Lee <sinquersw@...il.com>
To: Stanislav Fomichev <sdf@...gle.com>, bpf@...r.kernel.org
Cc: ast@...nel.org, daniel@...earbox.net, andrii@...nel.org,
 martin.lau@...ux.dev, song@...nel.org, yhs@...com, john.fastabend@...il.com,
 kpsingh@...nel.org, haoluo@...gle.com, jolsa@...nel.org,
 netdev@...r.kernel.org
Subject: Re: [RFC bpf-next 3/7] bpf: implement devtx hook points



On 6/12/23 10:23, Stanislav Fomichev wrote:
..... cut .....
> +
> +__diag_push();
> +__diag_ignore_all("-Wmissing-prototypes",
> +		  "Global functions as their definitions will be in vmlinux BTF");
> +
> +/**
> + * bpf_devtx_sb_attach - Attach devtx 'packet submit' program
> + * @ifindex: netdev interface index.
> + * @prog_fd: BPF program file descriptor.
> + *
> + * Return:
> + * * Returns 0 on success or ``-errno`` on error.
> + */
> +__bpf_kfunc int bpf_devtx_sb_attach(int ifindex, int prog_fd)
> +{
> +	struct net_device *netdev;
> +	int ret;
> +
> +	netdev = dev_get_by_index(current->nsproxy->net_ns, ifindex);
> +	if (!netdev)
> +		return -EINVAL;
> +
> +	mutex_lock(&devtx_attach_lock);
> +	ret = __bpf_devtx_attach(netdev, prog_fd, "devtx_sb", &netdev->devtx_sb);
> +	mutex_unlock(&devtx_attach_lock);
> +
> +	dev_put(netdev);
> +
> +	return ret;
> +}

How about adding another detach kfunc instead of overloading
this one? It is easier to understand.

> +
> +/**
> + * bpf_devtx_cp_attach - Attach devtx 'packet complete' program
> + * @ifindex: netdev interface index.
> + * @prog_fd: BPF program file descriptor.
> + *
> + * Return:
> + * * Returns 0 on success or ``-errno`` on error.
> + */
> +__bpf_kfunc int bpf_devtx_cp_attach(int ifindex, int prog_fd)
> +{
> +	struct net_device *netdev;
> +	int ret;
> +
> +	netdev = dev_get_by_index(current->nsproxy->net_ns, ifindex);
> +	if (!netdev)
> +		return -EINVAL;
> +
> +	mutex_lock(&devtx_attach_lock);
> +	ret = __bpf_devtx_attach(netdev, prog_fd, "devtx_cp", &netdev->devtx_cp);
> +	mutex_unlock(&devtx_attach_lock);
> +
> +	dev_put(netdev);
> +
> +	return ret;
> +}
> +
> +__diag_pop();
> +
> +bool is_devtx_kfunc(u32 kfunc_id)
> +{
> +	return !!btf_id_set8_contains(&bpf_devtx_hook_ids, kfunc_id);
> +}
> +
> +void devtx_shutdown(struct net_device *netdev)
> +{
> +	mutex_lock(&devtx_attach_lock);
> +	__bpf_devtx_detach(netdev, &netdev->devtx_sb);
> +	__bpf_devtx_detach(netdev, &netdev->devtx_cp);
> +	mutex_unlock(&devtx_attach_lock);
> +}
> +
> +BTF_SET8_START(bpf_devtx_syscall_kfunc_ids)
> +BTF_ID_FLAGS(func, bpf_devtx_sb_attach)
> +BTF_ID_FLAGS(func, bpf_devtx_cp_attach)
> +BTF_SET8_END(bpf_devtx_syscall_kfunc_ids)
> +
> +static const struct btf_kfunc_id_set bpf_devtx_syscall_kfunc_set = {
> +	.owner = THIS_MODULE,
> +	.set   = &bpf_devtx_syscall_kfunc_ids,
> +};
> +
> +static int __init devtx_init(void)
> +{
> +	int ret;
> +
> +	ret = register_btf_fmodret_id_set(&bpf_devtx_hook_set);
> +	if (ret) {
> +		pr_warn("failed to register devtx hooks: %d", ret);
> +		return ret;
> +	}
> +
> +	ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &bpf_devtx_syscall_kfunc_set);
> +	if (ret) {
> +		pr_warn("failed to register syscall kfuncs: %d", ret);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +late_initcall(devtx_init);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ