]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/net/ipsec: Fix Null pointer dereference in rtattr_pack()
authorLiu Ye <liuye@kylinos.cn>
Thu, 16 Jan 2025 01:30:37 +0000 (09:30 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:47:03 +0000 (12:47 +0100)
[ Upstream commit 3a0b7fa095212b51ed63892540c4f249991a2d74 ]

Address Null pointer dereference / undefined behavior in rtattr_pack
(note that size is 0 in the bad case).

Flagged by cppcheck as:
    tools/testing/selftests/net/ipsec.c:230:25: warning: Possible null pointer
    dereference: payload [nullPointer]
    memcpy(RTA_DATA(attr), payload, size);
                           ^
    tools/testing/selftests/net/ipsec.c:1618:54: note: Calling function 'rtattr_pack',
    4th argument 'NULL' value is 0
    if (rtattr_pack(&req.nh, sizeof(req), XFRMA_IF_ID, NULL, 0)) {
                                                       ^
    tools/testing/selftests/net/ipsec.c:230:25: note: Null pointer dereference
    memcpy(RTA_DATA(attr), payload, size);
                           ^
Signed-off-by: Liu Ye <liuye@kylinos.cn>
Link: https://patch.msgid.link/20250116013037.29470-1-liuye@kylinos.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/net/ipsec.c

index 03b048b6683154d2128c628945d9b2f5c7c14804..38f0de299605a9ff4855801711d40883578a5657 100644 (file)
@@ -189,7 +189,8 @@ static int rtattr_pack(struct nlmsghdr *nh, size_t req_sz,
 
        attr->rta_len = RTA_LENGTH(size);
        attr->rta_type = rta_type;
-       memcpy(RTA_DATA(attr), payload, size);
+       if (payload)
+               memcpy(RTA_DATA(attr), payload, size);
 
        return 0;
 }