From: Jiri Pirko <jiri@resnulli.us>
To: Ido Schimmel <idosch@nvidia.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, edumazet@google.com, nhorman@tuxdriver.com,
yotam.gi@gmail.com, johannes@sipsolutions.net,
jacob.e.keller@intel.com, horms@kernel.org,
andriy.shevchenko@linux.intel.com, jhs@mojatatu.com
Subject: Re: [PATCH net 1/2] psample: Require 'CAP_NET_ADMIN' when joining "packets" group
Date: Thu, 7 Dec 2023 11:17:10 +0100 [thread overview]
Message-ID: <ZXGbptl6uCNxR+3W@nanopsycho> (raw)
In-Reply-To: <20231206213102.1824398-2-idosch@nvidia.com>
Wed, Dec 06, 2023 at 10:31:01PM CET, idosch@nvidia.com wrote:
>The "psample" generic netlink family notifies sampled packets over the
>"packets" multicast group. This is problematic since by default generic
>netlink allows non-root users to listen to these notifications.
>
>Fix by marking the group with the 'GENL_UNS_ADMIN_PERM' flag. This will
>prevent non-root users or root without the 'CAP_NET_ADMIN' capability
>(in the user namespace owning the network namespace) from joining the
>group.
>
>Tested using [1].
>
>Before:
>
> # capsh -- -c ./psample_repo
> # capsh --drop=cap_net_admin -- -c ./psample_repo
>
>After:
>
> # capsh -- -c ./psample_repo
> # capsh --drop=cap_net_admin -- -c ./psample_repo
> Failed to join "packets" multicast group
>
>[1]
> $ cat psample.c
> #include <stdio.h>
> #include <netlink/genl/ctrl.h>
> #include <netlink/genl/genl.h>
> #include <netlink/socket.h>
>
> int join_grp(struct nl_sock *sk, const char *grp_name)
> {
> int grp, err;
>
> grp = genl_ctrl_resolve_grp(sk, "psample", grp_name);
> if (grp < 0) {
> fprintf(stderr, "Failed to resolve \"%s\" multicast group\n",
> grp_name);
> return grp;
> }
>
> err = nl_socket_add_memberships(sk, grp, NFNLGRP_NONE);
> if (err) {
> fprintf(stderr, "Failed to join \"%s\" multicast group\n",
> grp_name);
> return err;
> }
>
> return 0;
> }
>
> int main(int argc, char **argv)
> {
> struct nl_sock *sk;
> int err;
>
> sk = nl_socket_alloc();
> if (!sk) {
> fprintf(stderr, "Failed to allocate socket\n");
> return -1;
> }
>
> err = genl_connect(sk);
> if (err) {
> fprintf(stderr, "Failed to connect socket\n");
> return err;
> }
>
> err = join_grp(sk, "config");
> if (err)
> return err;
>
> err = join_grp(sk, "packets");
> if (err)
> return err;
>
> return 0;
> }
> $ gcc -I/usr/include/libnl3 -lnl-3 -lnl-genl-3 -o psample_repo psample.c
>
>Fixes: 6ae0a6286171 ("net: Introduce psample, a new genetlink channel for packet sampling")
>Reported-by: "The UK's National Cyber Security Centre (NCSC)" <security@ncsc.gov.uk>
>Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
next prev parent reply other threads:[~2023-12-07 10:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-06 21:31 [PATCH net 0/2] Generic netlink multicast fixes Ido Schimmel
2023-12-06 21:31 ` [PATCH net 1/2] psample: Require 'CAP_NET_ADMIN' when joining "packets" group Ido Schimmel
2023-12-06 23:16 ` Jacob Keller
2023-12-07 10:16 ` Jamal Hadi Salim
2023-12-07 10:32 ` Jiri Pirko
2023-12-07 10:17 ` Jiri Pirko [this message]
2023-12-06 21:31 ` [PATCH net 2/2] drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group Ido Schimmel
2023-12-06 23:19 ` Jacob Keller
2023-12-07 10:17 ` Jiri Pirko
2023-12-07 18:00 ` [PATCH net 0/2] Generic netlink multicast fixes patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZXGbptl6uCNxR+3W@nanopsycho \
--to=jiri@resnulli.us \
--cc=andriy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=jacob.e.keller@intel.com \
--cc=jhs@mojatatu.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
--cc=pabeni@redhat.com \
--cc=yotam.gi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox