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 48A1415DBBA; Thu, 13 Feb 2025 15:23:21 +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=1739460201; cv=none; b=txv7ALGKPs2iwhUf6bQRyxalwR5adbN6Wi4pSWIogSC/VHliAcFF0JNL07odD4bJ0ChAMb+pdNwHnViNktIMK4hN4V7tNxm2czedOitf8C6+0qT0vo+gFx48nYkBV+EkeQ2juRQ4ahCS9MtIOXqyaqapuJz0/2NWuzTr4i8QFeA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739460201; c=relaxed/simple; bh=7jvsnikbDWKZrKrsbnfRE86ecqg614W9mpFnwhUngKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oMFSIq3rW4jlqOaPJQh02Hbm0ocqb1Pz5zoXkazvT2BA5MHa/C3tdbm0E6/BTxqizwSMYBOWbrGrGvIHnh0Qt8NST/N/xkE0PDEhcJepee3VKilNNlz7gOmlbFlq3rITfMYdGJq19hTU7/9GKptIDs/QBfbScWGxFugZGSn6XD0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VSthABs4; 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="VSthABs4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C527DC4CED1; Thu, 13 Feb 2025 15:23:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739460201; bh=7jvsnikbDWKZrKrsbnfRE86ecqg614W9mpFnwhUngKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VSthABs4zxZJjGeFRiJjgveRFqwZBAQVGjmH8Dwknj+Pgy+Q3AE0GPAgIy85c9COU nzcqn0Xa0Ip2DYCsPOSj93xLudxTOPtK2YOUheEwgDHp8z6CsFPAeaBG1+QsjRacHB 73E3uNuMMhNZsdP7ESlOGtu716xXgH1DYSEpUe4k= 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.6 045/273] selftests/net/ipsec: Fix Null pointer dereference in rtattr_pack() Date: Thu, 13 Feb 2025 15:26:57 +0100 Message-ID: <20250213142409.132668452@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250213142407.354217048@linuxfoundation.org> References: <20250213142407.354217048@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-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