mnl_utils: sanitize incoming netlink payload size in callbacks
Subsystems (3)
PATCH 1/1 mnl_utils: sanitize incoming netlink payload size in callbacks
From: Jiri Pirko <[email protected]>
Don't trust the kernel to send payload of certain size. Sanitize that by checking the payload length in mnlu_cb_stop() and mnlu_cb_error() and only access the payload if it is of required size.
Note that for mnlu_cb_stop(), this is happening already for example with devlink resource. Kernel sends NLMSG_DONE with zero size payload.
--- lib/mnl_utils.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
lib/mnl_utils.c +6 -1
@@ -61,6 +61,8 @@ static int mnlu_cb_error(const struct nlmsghdr *nlh, void *data) {const struct nlmsgerr *err =mnl_nlmsg_get_payload (nlh); +if (mnl_nlmsg_get_payload_len (nlh) <sizeof (*err)) +return MNL_CB_STOP ;/* Netlink subsystems returns the errno value with different signess */ if (err->error <0 ) errno = -err->error;
@@ -75,8 +77,11 @@ static int mnlu_cb_error(const struct nlmsghdr *nlh, void *data)static int mnlu_cb_stop (const struct nlmsghdr *nlh,void *data) { -int len = *(int *)NLMSG_DATA (nlh); +int len; +if (mnl_nlmsg_get_payload_len (nlh) <sizeof (len)) +return MNL_CB_STOP ; + len = *(int *)mnl_nlmsg_get_payload (nlh);if (len <0 ) { errno = -len;nl_dump_ext_ack_done (nlh,sizeof (int ), len);
Signature · 1 line
2.41.0
This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:
Hello:
This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:
Quoted 10 lines · On Thu, 7 Dec 2023 13:53:51 +0100 you wrote:
From: Jiri Pirko <[email protected]>
Don't trust the kernel to send payload of certain size. Sanitize that by checking the payload length in
mnlu_cb_stop()andmnlu_cb_error()and only access the payload if it is of required size.Note that for
mnlu_cb_stop(), this is happening already for example with devlink resource. Kernel sendsNLMSG_DONEwith zero size payload.[...]
Here is the summary with links:
- [iproute2] mnl_utils: sanitize incoming netlink payload size in callbacks
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=1a68525f4613
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html