genetlink: Use internal flags for multicast groups
Subsystems (5)
PATCH 1/1 genetlink: Use internal flags for multicast groups
As explained in commit e03781879a0d ("drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group"), the "flags" field in the multicast group structure reuses uAPI flags despite the field not being exposed to user space. This makes it impossible to extend its use without adding new uAPI flags, which is inappropriate for internal kernel checks.
Solve this by adding internal flags (i.e., "GENL_MCAST_*") and convert the existing users to use them instead of the uAPI flags.
Tested using the reproducers in commit 44ec98ea5ea9 ("psample: Require 'CAP_NET_ADMIN' when joining "packets" group") and commit e03781879a0d ("drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group").
No functional changes intended.
--- include/net/genetlink.h | 7 ++++--- net/core/drop_monitor.c | 2 +- net/mptcp/pm_netlink.c | 2 +- net/netlink/genetlink.c | 4 ++-- net/psample/psample.c | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-)
include/net/genetlink.h +4 -3
@@ -8,16 +8,17 @@#define GENLMSG_DEFAULT_SIZE (NLMSG_DEFAULT_SIZE - GENL_HDRLEN) +#define GENL_MCAST_CAP_NET_ADMIN BIT(0) +#define GENL_MCAST_CAP_SYS_ADMIN BIT(1) +/** * struct genl_multicast_group - generic netlink multicast group * @name: name of the multicast group, names are per-family -* @flags: GENL_* flags (%GENL_ADMIN_PERM or %GENL_UNS_ADMIN_PERM) -* @cap_sys_admin: whether %CAP_SYS_ADMIN is required for binding +* @flags: GENL_MCAST_* flags */ struct genl_multicast_group {char name[GENL_NAMSIZ ];u8 flags; -u8 cap_sys_admin:1 ; };struct genl_split_ops ;
net/core/drop_monitor.c +1 -1
@@ -183,7 +183,7 @@ static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data) }static const struct genl_multicast_group dropmon_mcgrps[] = { - { .name ="events" , .cap_sys_admin =1 }, + { .name ="events" , .flags =GENL_MCAST_CAP_SYS_ADMIN , }, };static void send_dm_alert (struct work_struct *work)
net/mptcp/pm_netlink.c +1 -1
@@ -1100,7 +1100,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skcstatic const struct genl_multicast_group mptcp_pm_mcgrps[] = { [MPTCP_PM_CMD_GRP_OFFSET ] = { .name =MPTCP_PM_CMD_GRP_NAME , }, [MPTCP_PM_EV_GRP_OFFSET ] = { .name =MPTCP_PM_EV_GRP_NAME , - .flags =GENL_UNS_ADMIN_PERM , + .flags =GENL_MCAST_CAP_NET_ADMIN , }, };
net/netlink/genetlink.c +2 -2
@@ -1688,10 +1688,10 @@ static int genl_bind(struct net *net, int group)continue ; grp = &family->mcgrps[i]; -if ((grp->flags &GENL_UNS_ADMIN_PERM ) && +if ((grp->flags &GENL_MCAST_CAP_NET_ADMIN ) && !ns_capable (net->user_ns,CAP_NET_ADMIN )) ret = -EPERM ; -if (grp->cap_sys_admin && +if ((grp->flags &GENL_MCAST_CAP_SYS_ADMIN ) && !ns_capable (net->user_ns,CAP_SYS_ADMIN )) ret = -EPERM ;
net/psample/psample.c +1 -1
@@ -32,7 +32,7 @@ enum psample_nl_multicast_groups {static const struct genl_multicast_group psample_nl_mcgrps[] = { [PSAMPLE_NL_MCGRP_CONFIG ] = { .name =PSAMPLE_NL_MCGRP_CONFIG_NAME }, [PSAMPLE_NL_MCGRP_SAMPLE ] = { .name =PSAMPLE_NL_MCGRP_SAMPLE_NAME , - .flags =GENL_UNS_ADMIN_PERM }, + .flags =GENL_MCAST_CAP_NET_ADMIN , }, };static struct genl_family psample_nl_family__ro_after_init ;
Signature · 1 line
2.40.1
Re: genetlink: Use internal flags for multicast groups: Tests Results
Hi Ido,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5304333823115264
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5304333823115264/summary/summary.txt
- KVM Validation: debug (only selftest_mptcp_join):
- Unstable: 1 failed test(s): selftest_mptcp_join 🔴:
- Task: https://cirrus-ci.com/task/6148758753247232
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6148758753247232/summary/summary.txt
- KVM Validation: debug (except selftest_mptcp_join):
- Unstable: 1 failed test(s): packetdrill_regressions 🔴:
- Task: https://cirrus-ci.com/task/5022858846404608
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5022858846404608/summary/summary.txt
- KVM Validation: normal (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/6430233729957888
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6430233729957888/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/45531a413139
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-debugFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Quoted 15 lines · Ido Schimmel
As explained in commit
e03781879a0d("drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group"), the "flags" field in the multicast group structure reuses uAPI flags despite the field not being exposed to user space. This makes it impossible to extend its use without adding new uAPI flags, which is inappropriate for internal kernel checks.Solve this by adding internal flags (i.e., "GENL_MCAST_*") and convert the existing users to use them instead of the uAPI flags.
Tested using the reproducers in commit
44ec98ea5ea9("psample: Require 'CAP_NET_ADMIN' when joining "packets" group") and commite03781879a0d("drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group").No functional changes intended.
...
include/net/genetlink.h line 18
Quoted 10 lines
include/net/genetlink.h +4
-2+#define GENL_MCAST_CAP_NET_ADMIN BIT(0) +#define GENL_MCAST_CAP_SYS_ADMIN BIT(1) +/** * struct genl_multicast_group - generic netlink multicast group * @name: name of the multicast group, names are per-family -* @flags: GENL_* flags (%GENL_ADMIN_PERM or %GENL_UNS_ADMIN_PERM) -* @cap_sys_admin: whether %CAP_SYS_ADMIN is required for binding +* @flags: GENL_MCAST_* flags */
No functional, but documentation changes...
So, I suggest to have these flags being described
/* ... */
#define FLAG1
/* ... */
#define FLAG2
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
No functional, but documentation changes...
So, I suggest to have these flags being described
/* ... */
#define FLAG1/* ... */
#define FLAG2
OK, thanks. I will squash the following diff into v2:
include/net/genetlink.h +2 -0
@@ -8,7 +8,9 @@#define GENLMSG_DEFAULT_SIZE (NLMSG_DEFAULT_SIZE - GENL_HDRLEN) +/* Binding to multicast group requires %CAP_NET_ADMIN */ #define GENL_MCAST_CAP_NET_ADMIN BIT(0) +/* Binding to multicast group requires %CAP_SYS_ADMIN */ #define GENL_MCAST_CAP_SYS_ADMIN BIT(1)/**