Skip to content

Commit cd4d726

Browse files
idoschdavem330
authored andcommitted
genetlink: Use internal flags for multicast groups
As explained in commit e037818 ("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 44ec98e ("psample: Require 'CAP_NET_ADMIN' when joining "packets" group") and commit e037818 ("drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group"). No functional changes intended. Signed-off-by: Ido Schimmel <[email protected]> Reviewed-by: Mat Martineau <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f732ba4 commit cd4d726

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

include/net/genetlink.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88

99
#define GENLMSG_DEFAULT_SIZE (NLMSG_DEFAULT_SIZE - GENL_HDRLEN)
1010

11+
/* Binding to multicast group requires %CAP_NET_ADMIN */
12+
#define GENL_MCAST_CAP_NET_ADMIN BIT(0)
13+
/* Binding to multicast group requires %CAP_SYS_ADMIN */
14+
#define GENL_MCAST_CAP_SYS_ADMIN BIT(1)
15+
1116
/**
1217
* struct genl_multicast_group - generic netlink multicast group
1318
* @name: name of the multicast group, names are per-family
14-
* @flags: GENL_* flags (%GENL_ADMIN_PERM or %GENL_UNS_ADMIN_PERM)
15-
* @cap_sys_admin: whether %CAP_SYS_ADMIN is required for binding
19+
* @flags: GENL_MCAST_* flags
1620
*/
1721
struct genl_multicast_group {
1822
char name[GENL_NAMSIZ];
1923
u8 flags;
20-
u8 cap_sys_admin:1;
2124
};
2225

2326
struct genl_split_ops;

net/core/drop_monitor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data)
183183
}
184184

185185
static const struct genl_multicast_group dropmon_mcgrps[] = {
186-
{ .name = "events", .cap_sys_admin = 1 },
186+
{ .name = "events", .flags = GENL_MCAST_CAP_SYS_ADMIN, },
187187
};
188188

189189
static void send_dm_alert(struct work_struct *work)

net/mptcp/pm_netlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc
11001100
static const struct genl_multicast_group mptcp_pm_mcgrps[] = {
11011101
[MPTCP_PM_CMD_GRP_OFFSET] = { .name = MPTCP_PM_CMD_GRP_NAME, },
11021102
[MPTCP_PM_EV_GRP_OFFSET] = { .name = MPTCP_PM_EV_GRP_NAME,
1103-
.flags = GENL_UNS_ADMIN_PERM,
1103+
.flags = GENL_MCAST_CAP_NET_ADMIN,
11041104
},
11051105
};
11061106

net/netlink/genetlink.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,10 +1829,10 @@ static int genl_bind(struct net *net, int group)
18291829
continue;
18301830

18311831
grp = &family->mcgrps[i];
1832-
if ((grp->flags & GENL_UNS_ADMIN_PERM) &&
1832+
if ((grp->flags & GENL_MCAST_CAP_NET_ADMIN) &&
18331833
!ns_capable(net->user_ns, CAP_NET_ADMIN))
18341834
ret = -EPERM;
1835-
if (grp->cap_sys_admin &&
1835+
if ((grp->flags & GENL_MCAST_CAP_SYS_ADMIN) &&
18361836
!ns_capable(net->user_ns, CAP_SYS_ADMIN))
18371837
ret = -EPERM;
18381838

net/psample/psample.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ enum psample_nl_multicast_groups {
3232
static const struct genl_multicast_group psample_nl_mcgrps[] = {
3333
[PSAMPLE_NL_MCGRP_CONFIG] = { .name = PSAMPLE_NL_MCGRP_CONFIG_NAME },
3434
[PSAMPLE_NL_MCGRP_SAMPLE] = { .name = PSAMPLE_NL_MCGRP_SAMPLE_NAME,
35-
.flags = GENL_UNS_ADMIN_PERM },
35+
.flags = GENL_MCAST_CAP_NET_ADMIN, },
3636
};
3737

3838
static struct genl_family psample_nl_family __ro_after_init;

0 commit comments

Comments
 (0)