Skip to content

Commit c8777fa

Browse files
committed
Merge branch 'can-fixes-for-6-5-rc7'
Oliver Hartkopp says: ==================== CAN fixes for 6.5-rc7 The isotp fix removes an unnecessary check which leads to delays and/or a wrong error notification. The fix for the CAN_RAW socket solves the last issue that has been introduced with commit ee8b94c ("can: raw: fix receiver memory leak") in this upstream cycle (detected by Eric Dumazet). ==================== Link: https://lore.kernel.org/r/20230821144547.6658-1-socketcan@hartkopp.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents bf23ffc + c275a17 commit c8777fa

2 files changed

Lines changed: 33 additions & 24 deletions

File tree

net/can/isotp.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,6 @@ static bool isotp_register_rxid(struct isotp_sock *so)
188188
return (isotp_bc_flags(so) == 0);
189189
}
190190

191-
static bool isotp_register_txecho(struct isotp_sock *so)
192-
{
193-
/* all modes but SF_BROADCAST register for tx echo skbs */
194-
return (isotp_bc_flags(so) != CAN_ISOTP_SF_BROADCAST);
195-
}
196-
197191
static enum hrtimer_restart isotp_rx_timer_handler(struct hrtimer *hrtimer)
198192
{
199193
struct isotp_sock *so = container_of(hrtimer, struct isotp_sock,
@@ -1209,7 +1203,7 @@ static int isotp_release(struct socket *sock)
12091203
lock_sock(sk);
12101204

12111205
/* remove current filters & unregister */
1212-
if (so->bound && isotp_register_txecho(so)) {
1206+
if (so->bound) {
12131207
if (so->ifindex) {
12141208
struct net_device *dev;
12151209

@@ -1332,14 +1326,12 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)
13321326
can_rx_register(net, dev, rx_id, SINGLE_MASK(rx_id),
13331327
isotp_rcv, sk, "isotp", sk);
13341328

1335-
if (isotp_register_txecho(so)) {
1336-
/* no consecutive frame echo skb in flight */
1337-
so->cfecho = 0;
1329+
/* no consecutive frame echo skb in flight */
1330+
so->cfecho = 0;
13381331

1339-
/* register for echo skb's */
1340-
can_rx_register(net, dev, tx_id, SINGLE_MASK(tx_id),
1341-
isotp_rcv_echo, sk, "isotpe", sk);
1342-
}
1332+
/* register for echo skb's */
1333+
can_rx_register(net, dev, tx_id, SINGLE_MASK(tx_id),
1334+
isotp_rcv_echo, sk, "isotpe", sk);
13431335

13441336
dev_put(dev);
13451337

@@ -1560,7 +1552,7 @@ static void isotp_notify(struct isotp_sock *so, unsigned long msg,
15601552
case NETDEV_UNREGISTER:
15611553
lock_sock(sk);
15621554
/* remove current filters & unregister */
1563-
if (so->bound && isotp_register_txecho(so)) {
1555+
if (so->bound) {
15641556
if (isotp_register_rxid(so))
15651557
can_rx_unregister(dev_net(dev), dev, so->rxid,
15661558
SINGLE_MASK(so->rxid),

net/can/raw.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct raw_sock {
8585
int bound;
8686
int ifindex;
8787
struct net_device *dev;
88+
netdevice_tracker dev_tracker;
8889
struct list_head notifier;
8990
int loopback;
9091
int recv_own_msgs;
@@ -285,8 +286,10 @@ static void raw_notify(struct raw_sock *ro, unsigned long msg,
285286
case NETDEV_UNREGISTER:
286287
lock_sock(sk);
287288
/* remove current filters & unregister */
288-
if (ro->bound)
289+
if (ro->bound) {
289290
raw_disable_allfilters(dev_net(dev), dev, sk);
291+
netdev_put(dev, &ro->dev_tracker);
292+
}
290293

291294
if (ro->count > 1)
292295
kfree(ro->filter);
@@ -391,10 +394,12 @@ static int raw_release(struct socket *sock)
391394

392395
/* remove current filters & unregister */
393396
if (ro->bound) {
394-
if (ro->dev)
397+
if (ro->dev) {
395398
raw_disable_allfilters(dev_net(ro->dev), ro->dev, sk);
396-
else
399+
netdev_put(ro->dev, &ro->dev_tracker);
400+
} else {
397401
raw_disable_allfilters(sock_net(sk), NULL, sk);
402+
}
398403
}
399404

400405
if (ro->count > 1)
@@ -445,18 +450,20 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
445450
goto out;
446451
}
447452
if (dev->type != ARPHRD_CAN) {
448-
dev_put(dev);
449453
err = -ENODEV;
450-
goto out;
454+
goto out_put_dev;
451455
}
456+
452457
if (!(dev->flags & IFF_UP))
453458
notify_enetdown = 1;
454459

455460
ifindex = dev->ifindex;
456461

457462
/* filters set by default/setsockopt */
458463
err = raw_enable_allfilters(sock_net(sk), dev, sk);
459-
dev_put(dev);
464+
if (err)
465+
goto out_put_dev;
466+
460467
} else {
461468
ifindex = 0;
462469

@@ -467,18 +474,28 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
467474
if (!err) {
468475
if (ro->bound) {
469476
/* unregister old filters */
470-
if (ro->dev)
477+
if (ro->dev) {
471478
raw_disable_allfilters(dev_net(ro->dev),
472479
ro->dev, sk);
473-
else
480+
/* drop reference to old ro->dev */
481+
netdev_put(ro->dev, &ro->dev_tracker);
482+
} else {
474483
raw_disable_allfilters(sock_net(sk), NULL, sk);
484+
}
475485
}
476486
ro->ifindex = ifindex;
477487
ro->bound = 1;
488+
/* bind() ok -> hold a reference for new ro->dev */
478489
ro->dev = dev;
490+
if (ro->dev)
491+
netdev_hold(ro->dev, &ro->dev_tracker, GFP_KERNEL);
479492
}
480493

481-
out:
494+
out_put_dev:
495+
/* remove potential reference from dev_get_by_index() */
496+
if (dev)
497+
dev_put(dev);
498+
out:
482499
release_sock(sk);
483500
rtnl_unlock();
484501

0 commit comments

Comments
 (0)