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 B0E3448CDD; Mon, 1 Apr 2024 16:58: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=1711990691; cv=none; b=J3tkRFLpDOFHfx0f55ui1bAHJ3h8cZLNBlbyQdraj293gxbvZawo/zYfLgQXQH14kRkowvf0ojLozn4rDz+6OivZDS8E2gaUMOiadXgsXqGHPGoJBo5kXpfKgoOH9ai4LtLzgTFi5uztOFir+lKxm/K2HXdE28qkbK9xkglV88I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711990691; c=relaxed/simple; bh=QdHPO5SyAGOm/iGPTvRg5tmC9CtBuBUZLiKNuQDPoYE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pn9bf6KCv1mlZv8WKRT8iZ3G7sC+5VJ1J2pe6s3rqn8BQQrEtSgehVIkrbYyXKCELsjwYU9sr+daJYNXY9H9h96NGCdITNdUrmSrchboZK3yEJoAkxkcluAYxL2++sIf5vILvB98GUkPs9o8+aqeBQEAmrTD0IO6PIz7EskLaSM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wHZg1UWH; 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="wHZg1UWH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20C36C433C7; Mon, 1 Apr 2024 16:58:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1711990691; bh=QdHPO5SyAGOm/iGPTvRg5tmC9CtBuBUZLiKNuQDPoYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wHZg1UWHFtqiFU167id+A0xziv92XtVreT4eDlnlDT2WGqwT78Bd9kOhDLVEOoMj8 4OyGqSRK3dEicKk3+SASf3kaA/QfvfQeNXGIXIt3jIhkfjlaGRZjSMFJG/Ckn2LXLN Nqs1mDxqZKLViZiySIAQtOXAdw3no2s5tOtUAcBc= 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.1 037/272] kasan/test: avoid gcc warning for intentional overflow Date: Mon, 1 Apr 2024 17:43:47 +0200 Message-ID: <20240401152531.537015867@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240401152530.237785232@linuxfoundation.org> References: <20240401152530.237785232@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.1-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 0d59098f08761..cef683a2e0d2e 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test.c @@ -415,7 +415,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