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 43E5147A76; Mon, 1 Apr 2024 16:37:03 +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=1711989423; cv=none; b=DXZku86jAlkyWn68Joju+yVJxIPEJICdPgUhFozC+FUgH7jxB9xmLN5JetwaUUMxhNqw0Tf9HrDi4opoFJZaTdJIq1BalVjex7Q8sA+KVcHztIrHdA83qlnGKHpdW5g/ZlDhtrnVo/us5aWUYkIBP9HKmmP0RKOfrMgOwfd4kKA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711989423; c=relaxed/simple; bh=RdwGiSpSU8erjI4bOYhFV8zSPyZpah2moG0RWtNvIgg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HIGYoWKAZ0a+sEGQm5qhPYoj/DjiWfZHaj10KoIEPS0YFJ68v22hvpfhxihxaTRu6LSjTEKhvhmLo0lejRznswLkXTqleKKgFoOcDbBbObxbcbl6y112gY5KG/jKI7X0b/2MvIFatWtw0qhALHNKTyLs6gxJ1oCmr+5uT6h/zEc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=XlVyRruY; 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="XlVyRruY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7624C433F1; Mon, 1 Apr 2024 16:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1711989423; bh=RdwGiSpSU8erjI4bOYhFV8zSPyZpah2moG0RWtNvIgg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XlVyRruYhPcG7oG0tGy/2bGN+cpUKb2QkFIJcJ9Gj/fayZ6zlPENftdqWf+G0PZRr L7aycMYZbXtOeFwkUNfFixCvk/xmK2PMXMlByh6IxtruejQETNV3ZIqJ6KcX5PuO8N sGYDZlge35T/SHzTFD3fhKtBrZnQKDgk/n53gjnU= 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 6.6 043/396] kasan/test: avoid gcc warning for intentional overflow Date: Mon, 1 Apr 2024 17:41:32 +0200 Message-ID: <20240401152549.213251730@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240401152547.867452742@linuxfoundation.org> References: <20240401152547.867452742@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 6.6-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 --- mm/kasan/kasan_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c index b61cc6a42541a..0119075d2e58e 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test.c @@ -450,7 +450,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