Skip to content

Commit 9b64e93

Browse files
q2venPaolo Abeni
authored andcommitted
llc: Check netns in llc_dgram_match().
We will remove this restriction in llc_rcv() soon, which means that the protocol handler must be aware of netns. if (!net_eq(dev_net(dev), &init_net)) goto drop; llc_rcv() fetches llc_type_handlers[llc_pdu_type(skb) - 1] and calls it if not NULL. If the PDU type is LLC_DEST_SAP, llc_sap_handler() is called to pass skb to corresponding sockets. Then, we must look up a proper socket in the same netns with skb->dev. If the destination is a multicast address, llc_sap_handler() calls llc_sap_mcast(). It calculates a hash based on DSAP and skb->dev->ifindex, iterates on a socket list, and calls llc_mcast_match() to check if the socket is the correct destination. Then, llc_mcast_match() checks if skb->dev matches with llc_sk(sk)->dev. So, we need not check netns here. OTOH, if the destination is a unicast address, llc_sap_handler() calls llc_lookup_dgram() to look up a socket, but it does not check the netns. Therefore, we need to add netns check in llc_lookup_dgram(). Signed-off-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 9f9d4c1 commit 9b64e93

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

net/llc/llc_sap.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,25 +294,29 @@ static void llc_sap_rcv(struct llc_sap *sap, struct sk_buff *skb,
294294

295295
static inline bool llc_dgram_match(const struct llc_sap *sap,
296296
const struct llc_addr *laddr,
297-
const struct sock *sk)
297+
const struct sock *sk,
298+
const struct net *net)
298299
{
299300
struct llc_sock *llc = llc_sk(sk);
300301

301302
return sk->sk_type == SOCK_DGRAM &&
302-
llc->laddr.lsap == laddr->lsap &&
303-
ether_addr_equal(llc->laddr.mac, laddr->mac);
303+
net_eq(sock_net(sk), net) &&
304+
llc->laddr.lsap == laddr->lsap &&
305+
ether_addr_equal(llc->laddr.mac, laddr->mac);
304306
}
305307

306308
/**
307309
* llc_lookup_dgram - Finds dgram socket for the local sap/mac
308310
* @sap: SAP
309311
* @laddr: address of local LLC (MAC + SAP)
312+
* @net: netns to look up a socket in
310313
*
311314
* Search socket list of the SAP and finds connection using the local
312315
* mac, and local sap. Returns pointer for socket found, %NULL otherwise.
313316
*/
314317
static struct sock *llc_lookup_dgram(struct llc_sap *sap,
315-
const struct llc_addr *laddr)
318+
const struct llc_addr *laddr,
319+
const struct net *net)
316320
{
317321
struct sock *rc;
318322
struct hlist_nulls_node *node;
@@ -322,12 +326,12 @@ static struct sock *llc_lookup_dgram(struct llc_sap *sap,
322326
rcu_read_lock_bh();
323327
again:
324328
sk_nulls_for_each_rcu(rc, node, laddr_hb) {
325-
if (llc_dgram_match(sap, laddr, rc)) {
329+
if (llc_dgram_match(sap, laddr, rc, net)) {
326330
/* Extra checks required by SLAB_TYPESAFE_BY_RCU */
327331
if (unlikely(!refcount_inc_not_zero(&rc->sk_refcnt)))
328332
goto again;
329333
if (unlikely(llc_sk(rc)->sap != sap ||
330-
!llc_dgram_match(sap, laddr, rc))) {
334+
!llc_dgram_match(sap, laddr, rc, net))) {
331335
sock_put(rc);
332336
continue;
333337
}
@@ -429,7 +433,7 @@ void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb)
429433
llc_sap_mcast(sap, &laddr, skb);
430434
kfree_skb(skb);
431435
} else {
432-
struct sock *sk = llc_lookup_dgram(sap, &laddr);
436+
struct sock *sk = llc_lookup_dgram(sap, &laddr, dev_net(skb->dev));
433437
if (sk) {
434438
llc_sap_rcv(sap, skb, sk);
435439
sock_put(sk);

0 commit comments

Comments
 (0)