Skip to content

Commit cce598f

Browse files
Merge patch series "can: fix can-gw Out-of-Bounds Heap R/W and isotp UAF"
Marc Kleine-Budde <[email protected]> says: This series is by Ali Norouzi and Oliver Hartkopp fixing a can-gw Out-of-Bounds Heap R/W and can-isotp UAF. Link: https://patch.msgid.link/20260319-fix-can-gw-and-can-isotp-v2-0-c45d52c6d2d8@pengutronix.de Signed-off-by: Marc Kleine-Budde <[email protected]>
2 parents 46eee16 + 424e95d commit cce598f

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

net/can/gw.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,10 @@ static void cgw_csum_crc8_rel(struct canfd_frame *cf,
375375
return;
376376

377377
if (from <= to) {
378-
for (i = crc8->from_idx; i <= crc8->to_idx; i++)
378+
for (i = from; i <= to; i++)
379379
crc = crc8->crctab[crc ^ cf->data[i]];
380380
} else {
381-
for (i = crc8->from_idx; i >= crc8->to_idx; i--)
381+
for (i = from; i >= to; i--)
382382
crc = crc8->crctab[crc ^ cf->data[i]];
383383
}
384384

@@ -397,7 +397,7 @@ static void cgw_csum_crc8_rel(struct canfd_frame *cf,
397397
break;
398398
}
399399

400-
cf->data[crc8->result_idx] = crc ^ crc8->final_xor_val;
400+
cf->data[res] = crc ^ crc8->final_xor_val;
401401
}
402402

403403
static void cgw_csum_crc8_pos(struct canfd_frame *cf,

net/can/isotp.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,12 +1248,6 @@ static int isotp_release(struct socket *sock)
12481248
so->ifindex = 0;
12491249
so->bound = 0;
12501250

1251-
if (so->rx.buf != so->rx.sbuf)
1252-
kfree(so->rx.buf);
1253-
1254-
if (so->tx.buf != so->tx.sbuf)
1255-
kfree(so->tx.buf);
1256-
12571251
sock_orphan(sk);
12581252
sock->sk = NULL;
12591253

@@ -1622,6 +1616,21 @@ static int isotp_notifier(struct notifier_block *nb, unsigned long msg,
16221616
return NOTIFY_DONE;
16231617
}
16241618

1619+
static void isotp_sock_destruct(struct sock *sk)
1620+
{
1621+
struct isotp_sock *so = isotp_sk(sk);
1622+
1623+
/* do the standard CAN sock destruct work */
1624+
can_sock_destruct(sk);
1625+
1626+
/* free potential extended PDU buffers */
1627+
if (so->rx.buf != so->rx.sbuf)
1628+
kfree(so->rx.buf);
1629+
1630+
if (so->tx.buf != so->tx.sbuf)
1631+
kfree(so->tx.buf);
1632+
}
1633+
16251634
static int isotp_init(struct sock *sk)
16261635
{
16271636
struct isotp_sock *so = isotp_sk(sk);
@@ -1666,6 +1675,9 @@ static int isotp_init(struct sock *sk)
16661675
list_add_tail(&so->notifier, &isotp_notifier_list);
16671676
spin_unlock(&isotp_notifier_lock);
16681677

1678+
/* re-assign default can_sock_destruct() reference */
1679+
sk->sk_destruct = isotp_sock_destruct;
1680+
16691681
return 0;
16701682
}
16711683

0 commit comments

Comments
 (0)