Skip to content

Commit c78ebe1

Browse files
qsndavem330
authored andcommitted
macsec: fix reference counting on RXSC in macsec_handle_frame
Currently, we lookup the RXSC without taking a reference on it. The RXSA holds a reference on the RXSC, but the SA and SC could still both disappear before we take a reference on the SA. Take a reference on the RXSC in macsec_handle_frame. Fixes: c09440f ("macsec: introduce IEEE 802.1AE driver") Signed-off-by: Sabrina Dubroca <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 122e9b7 commit c78ebe1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/net/macsec.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ static void macsec_decrypt_done(struct crypto_async_request *base, int err)
863863
struct net_device *dev = skb->dev;
864864
struct macsec_dev *macsec = macsec_priv(dev);
865865
struct macsec_rx_sa *rx_sa = macsec_skb_cb(skb)->rx_sa;
866+
struct macsec_rx_sc *rx_sc = rx_sa->sc;
866867
int len, ret;
867868
u32 pn;
868869

@@ -891,6 +892,7 @@ static void macsec_decrypt_done(struct crypto_async_request *base, int err)
891892

892893
out:
893894
macsec_rxsa_put(rx_sa);
895+
macsec_rxsc_put(rx_sc);
894896
dev_put(dev);
895897
}
896898

@@ -1106,6 +1108,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
11061108

11071109
list_for_each_entry_rcu(macsec, &rxd->secys, secys) {
11081110
struct macsec_rx_sc *sc = find_rx_sc(&macsec->secy, sci);
1111+
sc = sc ? macsec_rxsc_get(sc) : NULL;
11091112

11101113
if (sc) {
11111114
secy = &macsec->secy;
@@ -1180,8 +1183,10 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
11801183

11811184
if (IS_ERR(skb)) {
11821185
/* the decrypt callback needs the reference */
1183-
if (PTR_ERR(skb) != -EINPROGRESS)
1186+
if (PTR_ERR(skb) != -EINPROGRESS) {
11841187
macsec_rxsa_put(rx_sa);
1188+
macsec_rxsc_put(rx_sc);
1189+
}
11851190
rcu_read_unlock();
11861191
*pskb = NULL;
11871192
return RX_HANDLER_CONSUMED;
@@ -1197,6 +1202,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
11971202

11981203
if (rx_sa)
11991204
macsec_rxsa_put(rx_sa);
1205+
macsec_rxsc_put(rx_sc);
12001206

12011207
ret = gro_cells_receive(&macsec->gro_cells, skb);
12021208
if (ret == NET_RX_SUCCESS)
@@ -1212,6 +1218,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
12121218
drop:
12131219
macsec_rxsa_put(rx_sa);
12141220
drop_nosa:
1221+
macsec_rxsc_put(rx_sc);
12151222
rcu_read_unlock();
12161223
drop_direct:
12171224
kfree_skb(skb);

0 commit comments

Comments
 (0)