Subject: Re: [PATCH] netfilter: Record uid and gid in xt_AUDIT

From: Florian Westphal <[email-masked]>
Date: Wed, 9 Oct 2024 23:33:45 +0200

Richard Weinberger <[email-masked]> wrote:
> When recording audit events for new outgoing connections,
> it is helpful to log the user info of the associated socket,
> if available.
> Therefore, check if the skb has a socket, and if it does,
> log the owning fsuid/fsgid.

AFAIK audit isn't namespace aware at all (neither netns nor userns), so I
wonder how to handle this.

We can't reject adding a -j AUDIT rule for non-init-net (we could, but I'm sure
it'll break some setups...).

But I wonder if we should at least skip the uid if the user namespace is
'something else'.

> +	if (sk && sk_fullsock(sk)) {

I.e. check net->user_ns == &init_user_ns too and don't log the uid
otherwise.

I don't think auditd can make sense of the uid otherwise, resp.
its misleading, no?

Alternatively, use this instead?

kuid = sock_net_uid(sock_net(sk), sk);
from_kuid_munged(sock_net(sk)->user_ns, kuid);

There is no need to follow ->file backpointer anymore, see
6acc5c2910689fc6ee181bf63085c5efff6a42bd and
86741ec25462e4c8cdce6df2f41ead05568c7d5e,
"net: core: Add a UID field to struct sock.".

I think we could streamline all the existing paths that fetch uid
from sock->file to not do that and use sock_net_uid() instead as well.