Skip to content

Commit eb660ac

Browse files
author
CKI KWF Bot
committed
Merge: CVE-2025-39925: can: j1939: implement NETDEV_UNREGISTER notification handler
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7521 JIRA: https://issues.redhat.com/browse/RHEL-124106 CVE: CVE-2025-39925 * 7fcbe5b can: j1939: implement NETDEV_UNREGISTER notification handler * 93a27b5 can: j1939: add missing calls in NETDEV_UNREGISTER notification handler Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com> --- <small>Created 2025-10-25 21:33 UTC by backporter - [KWF FAQ](https://red.ht/kernel_workflow_doc) - [Slack #team-kernel-workflow](https://redhat-internal.slack.com/archives/C04LRUPMJQ5) - [Source](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/webhook/utils/backporter.py) - [Documentation](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/docs/README.backporter.md) - [Report an issue](https://issues.redhat.com/secure/CreateIssueDetails!init.jspa?pid=12334433&issuetype=1&priority=4&summary=backporter+webhook+issue&components=kernel-workflow+/+backporter)</small> Approved-by: Radu Rendec <rrendec@redhat.com> Approved-by: Davide Caratti <dcaratti@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents 9ed685a + 08c24ea commit eb660ac

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

net/can/j1939/j1939-priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ void j1939_priv_get(struct j1939_priv *priv);
212212

213213
/* notify/alert all j1939 sockets bound to ifindex */
214214
void j1939_sk_netdev_event_netdown(struct j1939_priv *priv);
215+
void j1939_sk_netdev_event_unregister(struct j1939_priv *priv);
215216
int j1939_cancel_active_session(struct j1939_priv *priv, struct sock *sk);
216217
void j1939_tp_init(struct j1939_priv *priv);
217218

net/can/j1939/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ static int j1939_netdev_notify(struct notifier_block *nb,
381381
j1939_sk_netdev_event_netdown(priv);
382382
j1939_ecu_unmap_all(priv);
383383
break;
384+
case NETDEV_UNREGISTER:
385+
j1939_cancel_active_session(priv, NULL);
386+
j1939_sk_netdev_event_netdown(priv);
387+
j1939_sk_netdev_event_unregister(priv);
388+
break;
384389
}
385390

386391
j1939_priv_put(priv);

net/can/j1939/socket.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,55 @@ void j1939_sk_netdev_event_netdown(struct j1939_priv *priv)
12961296
read_unlock_bh(&priv->j1939_socks_lock);
12971297
}
12981298

1299+
void j1939_sk_netdev_event_unregister(struct j1939_priv *priv)
1300+
{
1301+
struct sock *sk;
1302+
struct j1939_sock *jsk;
1303+
bool wait_rcu = false;
1304+
1305+
rescan: /* The caller is holding a ref on this "priv" via j1939_priv_get_by_ndev(). */
1306+
read_lock_bh(&priv->j1939_socks_lock);
1307+
list_for_each_entry(jsk, &priv->j1939_socks, list) {
1308+
/* Skip if j1939_jsk_add() is not called on this socket. */
1309+
if (!(jsk->state & J1939_SOCK_BOUND))
1310+
continue;
1311+
sk = &jsk->sk;
1312+
sock_hold(sk);
1313+
read_unlock_bh(&priv->j1939_socks_lock);
1314+
/* Check if j1939_jsk_del() is not yet called on this socket after holding
1315+
* socket's lock, for both j1939_sk_bind() and j1939_sk_release() call
1316+
* j1939_jsk_del() with socket's lock held.
1317+
*/
1318+
lock_sock(sk);
1319+
if (jsk->state & J1939_SOCK_BOUND) {
1320+
/* Neither j1939_sk_bind() nor j1939_sk_release() called j1939_jsk_del().
1321+
* Make this socket no longer bound, by pretending as if j1939_sk_bind()
1322+
* dropped old references but did not get new references.
1323+
*/
1324+
j1939_jsk_del(priv, jsk);
1325+
j1939_local_ecu_put(priv, jsk->addr.src_name, jsk->addr.sa);
1326+
j1939_netdev_stop(priv);
1327+
/* Call j1939_priv_put() now and prevent j1939_sk_sock_destruct() from
1328+
* calling the corresponding j1939_priv_put().
1329+
*
1330+
* j1939_sk_sock_destruct() is supposed to call j1939_priv_put() after
1331+
* an RCU grace period. But since the caller is holding a ref on this
1332+
* "priv", we can defer synchronize_rcu() until immediately before
1333+
* the caller calls j1939_priv_put().
1334+
*/
1335+
j1939_priv_put(priv);
1336+
jsk->priv = NULL;
1337+
wait_rcu = true;
1338+
}
1339+
release_sock(sk);
1340+
sock_put(sk);
1341+
goto rescan;
1342+
}
1343+
read_unlock_bh(&priv->j1939_socks_lock);
1344+
if (wait_rcu)
1345+
synchronize_rcu();
1346+
}
1347+
12991348
static int j1939_sk_no_ioctlcmd(struct socket *sock, unsigned int cmd,
13001349
unsigned long arg)
13011350
{

0 commit comments

Comments
 (0)