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 A5EBF71742; Mon, 8 Apr 2024 13:04:11 +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=1712581451; cv=none; b=cAFdvzb0qQCb+AkvoVs8k0VcDXkh/qM+WS/SDAq91qPpj0VyphDer8QTPHKrNjI1tyz2ZBnMYbSUIlU9qFAFTsaM9qzvYmIZHoX9K7DyGLme8SMKxf+xVEwn3VGG8S0w6IQlhFZ0FjvhijvCDp7FhcMDuG01jx0Io5Yg8J0za2E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712581451; c=relaxed/simple; bh=mPK554PXDzQ6B8/NLmDcB8dIJIixzJYQ97UwQIQ4fks=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NPjfx76BkRjorjMKYkzgNFEhKERTZy/XwbeCGIfNj4VmGW086IzL/M+MEi9M/zaUwiNd3SwUcA7USLwf7U5xzvXBTd7VBesuLKFMr9J60ZIyzq9KAWfe3qKEBuwFjNfy3d+8R0cqqe9VL3a8QHgEDaS1qwMdk1vR0EDXxstWcR8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=V159dWb0; 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="V159dWb0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CF5BC433F1; Mon, 8 Apr 2024 13:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712581451; bh=mPK554PXDzQ6B8/NLmDcB8dIJIixzJYQ97UwQIQ4fks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V159dWb0p2qczleD0Tua0bkzLS8C+OHQb6glKIz5Y9w4CRpet3N8+i3/nMWc7ekj1 X6oFmdqFPG5Pv54aHn76FQeNghpVnFMGDQVj5sI1kMB6FresJejoiILiCNcg4jX4jf nMzJOTMLUFUfrD4MpzJZJQbDaCXBqwCjq4K1NGaY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Arnd Bergmann , Andrey Konovalov , Alexander Potapenko , Andrey Ryabinin , Dmitry Vyukov , Marco Elver , Vincenzo Frascino , Andrew Morton , Sasha Levin Subject: [PATCH 5.15 028/690] kasan/test: avoid gcc warning for intentional overflow Date: Mon, 8 Apr 2024 14:48:14 +0200 Message-ID: <20240408125400.579811732@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408125359.506372836@linuxfoundation.org> References: <20240408125359.506372836@linuxfoundation.org> User-Agent: quilt/0.67 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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnd Bergmann [ Upstream commit e10aea105e9ed14b62a11844fec6aaa87c6935a3 ] The out-of-bounds test allocates an object that is three bytes too short in order to validate the bounds checking. Starting with gcc-14, this causes a compile-time warning as gcc has grown smart enough to understand the sizeof() logic: mm/kasan/kasan_test.c: In function 'kmalloc_oob_16': mm/kasan/kasan_test.c:443:14: error: allocation of insufficient size '13' for type 'struct ' with size '16' [-Werror=alloc-size] 443 | ptr1 = kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL); | ^ Hide the actual computation behind a RELOC_HIDE() that ensures the compiler misses the intentional bug. Link: https://lkml.kernel.org/r/20240212111609.869266-1-arnd@kernel.org Fixes: 3f15801cdc23 ("lib: add kasan test module") Signed-off-by: Arnd Bergmann Reviewed-by: Andrey Konovalov Cc: Alexander Potapenko Cc: Andrey Ryabinin Cc: Arnd Bergmann Cc: Dmitry Vyukov Cc: Marco Elver Cc: Vincenzo Frascino Cc: Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- lib/test_kasan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/test_kasan.c b/lib/test_kasan.c index f0b8b05ccf194..ffedc34714ba7 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -403,7 +403,8 @@ static void kmalloc_oob_16(struct kunit *test) /* This test is specifically crafted for the generic mode. */ KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); - ptr1 = kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL); + /* RELOC_HIDE to prevent gcc from warning about short alloc */ + ptr1 = RELOC_HIDE(kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL), 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); ptr2 = kmalloc(sizeof(*ptr2), GFP_KERNEL); -- 2.43.0