]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
net: mctp: defer creation of dst after source-address check
authorJeremy Kerr <jk@codeconstruct.com.au>
Fri, 3 Apr 2026 02:24:51 +0000 (10:24 +0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 7 Apr 2026 01:06:47 +0000 (18:06 -0700)
commitf32ba0963119b2520127077d72ebe7f6f8cb847f
treec6ac025242162155846730e7da6a0186e3c45a07
parent70e32aadb5cab9ef706962e1293582ec03f89625
net: mctp: defer creation of dst after source-address check

Sashiko reports:

> mctp_dst_from_route() increments the device reference count by calling
> mctp_dev_hold(). When a valid route is found and dst is NULL, the
> structure copy is bypassed and rc is set to 0.

Instead of optimistically creating a dst from the final route (then
releasing it if the saddr is invalid), perform the saddr check first.

This means we don't have an unuecessary hold/release on the dev, which
could leak if the dst pointer is NULL. No caller passes a NULL dst at
present though (so the leak is not possible), but this is an intended
use of mctp_dst_from_route().

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20260403-dev-mctp-dst-defer-v1-1-9c2c55faf9e9@codeconstruct.com.au
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/mctp/route.c