Skip to content

Commit

Permalink
netfilter: nft_socket: make cgroup match work in input too
Browse files Browse the repository at this point in the history
cgroupv2 helper function ignores the already-looked up sk
and uses skb->sk instead.

Just pass sk from the calling function instead; this will
make cgroup matching work for udp and tcp in input even when
edemux did not set skb->sk already.

Fixes: e0bb96d ("netfilter: nft_socket: add support for cgroupsv2")
Signed-off-by: Florian Westphal <[email protected]>
Tested-by: Topi Miettinen <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
Florian Westphal authored and ummakynes committed Apr 11, 2022
1 parent e8a64bb commit 05ae2fb
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions net/netfilter/nft_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ static void nft_socket_wildcard(const struct nft_pktinfo *pkt,

#ifdef CONFIG_SOCK_CGROUP_DATA
static noinline bool
nft_sock_get_eval_cgroupv2(u32 *dest, const struct nft_pktinfo *pkt, u32 level)
nft_sock_get_eval_cgroupv2(u32 *dest, struct sock *sk, const struct nft_pktinfo *pkt, u32 level)
{
struct sock *sk = skb_to_full_sk(pkt->skb);
struct cgroup *cgrp;

if (!sk || !sk_fullsock(sk) || !net_eq(nft_net(pkt), sock_net(sk)))
if (!sk_fullsock(sk))
return false;

cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data);
Expand Down Expand Up @@ -109,7 +108,7 @@ static void nft_socket_eval(const struct nft_expr *expr,
break;
#ifdef CONFIG_SOCK_CGROUP_DATA
case NFT_SOCKET_CGROUPV2:
if (!nft_sock_get_eval_cgroupv2(dest, pkt, priv->level)) {
if (!nft_sock_get_eval_cgroupv2(dest, sk, pkt, priv->level)) {
regs->verdict.code = NFT_BREAK;
return;
}
Expand Down

0 comments on commit 05ae2fb

Please sign in to comment.