Skip to content

Commit a041ade

Browse files
committed
Merge branch 'generic-netlink-multicast-fixes'
Ido Schimmel says: ==================== Generic netlink multicast fixes Restrict two generic netlink multicast groups - in the "psample" and "NET_DM" families - to be root-only with the appropriate capabilities. See individual patches for more details. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 4a02609 + e037818 commit a041ade

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

include/net/genetlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
* struct genl_multicast_group - generic netlink multicast group
1313
* @name: name of the multicast group, names are per-family
1414
* @flags: GENL_* flags (%GENL_ADMIN_PERM or %GENL_UNS_ADMIN_PERM)
15+
* @cap_sys_admin: whether %CAP_SYS_ADMIN is required for binding
1516
*/
1617
struct genl_multicast_group {
1718
char name[GENL_NAMSIZ];
1819
u8 flags;
20+
u8 cap_sys_admin:1;
1921
};
2022

2123
struct genl_split_ops;

net/core/drop_monitor.c

Lines changed: 3 additions & 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", },
186+
{ .name = "events", .cap_sys_admin = 1 },
187187
};
188188

189189
static void send_dm_alert(struct work_struct *work)
@@ -1619,11 +1619,13 @@ static const struct genl_small_ops dropmon_ops[] = {
16191619
.cmd = NET_DM_CMD_START,
16201620
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16211621
.doit = net_dm_cmd_trace,
1622+
.flags = GENL_ADMIN_PERM,
16221623
},
16231624
{
16241625
.cmd = NET_DM_CMD_STOP,
16251626
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
16261627
.doit = net_dm_cmd_trace,
1628+
.flags = GENL_ADMIN_PERM,
16271629
},
16281630
{
16291631
.cmd = NET_DM_CMD_CONFIG_GET,

net/netlink/genetlink.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,9 @@ static int genl_bind(struct net *net, int group)
16911691
if ((grp->flags & GENL_UNS_ADMIN_PERM) &&
16921692
!ns_capable(net->user_ns, CAP_NET_ADMIN))
16931693
ret = -EPERM;
1694+
if (grp->cap_sys_admin &&
1695+
!ns_capable(net->user_ns, CAP_SYS_ADMIN))
1696+
ret = -EPERM;
16941697

16951698
break;
16961699
}

net/psample/psample.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ enum psample_nl_multicast_groups {
3131

3232
static const struct genl_multicast_group psample_nl_mcgrps[] = {
3333
[PSAMPLE_NL_MCGRP_CONFIG] = { .name = PSAMPLE_NL_MCGRP_CONFIG_NAME },
34-
[PSAMPLE_NL_MCGRP_SAMPLE] = { .name = PSAMPLE_NL_MCGRP_SAMPLE_NAME },
34+
[PSAMPLE_NL_MCGRP_SAMPLE] = { .name = PSAMPLE_NL_MCGRP_SAMPLE_NAME,
35+
.flags = GENL_UNS_ADMIN_PERM },
3536
};
3637

3738
static struct genl_family psample_nl_family __ro_after_init;

0 commit comments

Comments
 (0)