From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F11D71DF24D; Wed, 19 Feb 2025 09:19:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739956792; cv=none; b=UfkcUa57rh0rlwU2Q4v3BEr11lSUrC0PSrTNT69yY73O5/CISue4Q9OZ9/jnQ2gk5AYhy7k1wz8OMcl6tGf4KkvK8+/yDu/ZLpdKuGPas3AtnnJgH33NhgcIJsTjfL269K2PjG5bpIToYyKBkdWyLir+buWXEcQkr9yUprn+Vbo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739956792; c=relaxed/simple; bh=X0eSu9vqS6/j+OGuhEtHCVKF/6LEeUtlFespJceNSjk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OrX+G32OL4Hyk8GPLfsvqUTBXyeq8FdKOeM6uxYgbgL7ShurrDVR7S+Oiea+8wVmtkkoMB33hjbu+tmiEBK0Ou1h4rSOsATw98Bul46X2PCofwelyvWNnkwjc5QzemUMziiRiZ24w1fDkhqGLM0XOf1gNz+YUl6VLdWf2IlT7eo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZCVGcBo0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ZCVGcBo0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70944C4CED1; Wed, 19 Feb 2025 09:19:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739956791; bh=X0eSu9vqS6/j+OGuhEtHCVKF/6LEeUtlFespJceNSjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZCVGcBo0BVze2OS6kOgbjxhcYzXVr/DFhZyJRKvIE5jPJr+DaYHqF2a1DeZmM3Wb6 J9dB1Jd6+TDNTQNpYkBlFijZp89ndV2+IvVdpxChPagNFVudC/geMp1X86CgdfWhWz H/++EyNA5nOWPSCcDQBLSSYGpd/Culfry+Lcx2zo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Liu Ye , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1 301/578] selftests/net/ipsec: Fix Null pointer dereference in rtattr_pack() Date: Wed, 19 Feb 2025 09:25:05 +0100 Message-ID: <20250219082704.858694269@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219082652.891560343@linuxfoundation.org> References: <20250219082652.891560343@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Liu Ye [ 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 Link: https://patch.msgid.link/20250116013037.29470-1-liuye@kylinos.cn Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- tools/testing/selftests/net/ipsec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/ipsec.c b/tools/testing/selftests/net/ipsec.c index be4a30a0d02ae..9b44a091802cb 100644 --- a/tools/testing/selftests/net/ipsec.c +++ b/tools/testing/selftests/net/ipsec.c @@ -227,7 +227,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; } -- 2.39.5