* [PATCH net-next] genetlink: Use internal flags for multicast groups
@ 2023-12-17 7:53 Ido Schimmel
2023-12-18 11:37 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Ido Schimmel @ 2023-12-17 7:53 UTC (permalink / raw)
To: netdev, mptcp
Cc: davem, kuba, pabeni, edumazet, nhorman, matttbe, martineau,
yotam.gi, jiri, jacob.e.keller, johannes, andriy.shevchenko, fw,
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 commit e03781879a0d
("drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group").
No functional changes intended.
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
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(-)
diff --git a/include/net/genetlink.h b/include/net/genetlink.h
index c53244f20437..5a402fd24817 100644
--- a/include/net/genetlink.h
+++ b/include/net/genetlink.h
@@ -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;
diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c
index b240d9aae4a6..b0f221d658be 100644
--- a/net/core/drop_monitor.c
+++ b/net/core/drop_monitor.c
@@ -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)
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index bf4d96f6f99a..272e93be1aad 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1100,7 +1100,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc
static 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,
},
};
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 9c7ffd10df2a..f6d14c092d24 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -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;
diff --git a/net/psample/psample.c b/net/psample/psample.c
index c34e902855db..ddd211a151d0 100644
--- a/net/psample/psample.c
+++ b/net/psample/psample.c
@@ -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;
--
2.40.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] genetlink: Use internal flags for multicast groups
2023-12-17 7:53 [PATCH net-next] genetlink: Use internal flags for multicast groups Ido Schimmel
@ 2023-12-18 11:37 ` Andy Shevchenko
2023-12-18 16:31 ` Ido Schimmel
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2023-12-18 11:37 UTC (permalink / raw)
To: Ido Schimmel
Cc: netdev, mptcp, davem, kuba, pabeni, edumazet, nhorman, matttbe,
martineau, yotam.gi, jiri, jacob.e.keller, johannes, fw
On Sun, Dec 17, 2023 at 09:53:48AM +0200, Ido Schimmel wrote:
> 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.
...
> +#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
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] genetlink: Use internal flags for multicast groups
2023-12-18 11:37 ` Andy Shevchenko
@ 2023-12-18 16:31 ` Ido Schimmel
0 siblings, 0 replies; 3+ messages in thread
From: Ido Schimmel @ 2023-12-18 16:31 UTC (permalink / raw)
To: Andy Shevchenko
Cc: netdev, mptcp, davem, kuba, pabeni, edumazet, nhorman, matttbe,
martineau, yotam.gi, jiri, jacob.e.keller, johannes, fw
On Mon, Dec 18, 2023 at 01:37:41PM +0200, Andy Shevchenko wrote:
> 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:
diff --git a/include/net/genetlink.h b/include/net/genetlink.h
index 5a402fd24817..bd6a6ffdec76 100644
--- a/include/net/genetlink.h
+++ b/include/net/genetlink.h
@@ -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)
/**
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-18 16:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-17 7:53 [PATCH net-next] genetlink: Use internal flags for multicast groups Ido Schimmel
2023-12-18 11:37 ` Andy Shevchenko
2023-12-18 16:31 ` Ido Schimmel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).