From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Mikulas Patocka <mpatocka@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Sasha Levin <sashal@kernel.org>,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org,
peterz@infradead.org, jpoimboe@redhat.com
Subject: [PATCH AUTOSEL 5.10 5/9] x86: __memcpy_flushcache: fix wrong alignment if size > 2^32
Date: Tue, 26 Apr 2022 15:02:26 -0400 [thread overview]
Message-ID: <20220426190232.2351606-5-sashal@kernel.org> (raw)
In-Reply-To: <20220426190232.2351606-1-sashal@kernel.org>
From: Mikulas Patocka <mpatocka@redhat.com>
[ Upstream commit a6823e4e360fe975bd3da4ab156df7c74c8b07f3 ]
The first "if" condition in __memcpy_flushcache is supposed to align the
"dest" variable to 8 bytes and copy data up to this alignment. However,
this condition may misbehave if "size" is greater than 4GiB.
The statement min_t(unsigned, size, ALIGN(dest, 8) - dest); casts both
arguments to unsigned int and selects the smaller one. However, the
cast truncates high bits in "size" and it results in misbehavior.
For example:
suppose that size == 0x100000001, dest == 0x200000002
min_t(unsigned, size, ALIGN(dest, 8) - dest) == min_t(0x1, 0xe) == 0x1;
...
dest += 0x1;
so we copy just one byte "and" dest remains unaligned.
This patch fixes the bug by replacing unsigned with size_t.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
arch/x86/lib/usercopy_64.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
index 508c81e97ab1..f1c0befb62df 100644
--- a/arch/x86/lib/usercopy_64.c
+++ b/arch/x86/lib/usercopy_64.c
@@ -121,7 +121,7 @@ void __memcpy_flushcache(void *_dst, const void *_src, size_t size)
/* cache copy and flush to align dest */
if (!IS_ALIGNED(dest, 8)) {
- unsigned len = min_t(unsigned, size, ALIGN(dest, 8) - dest);
+ size_t len = min_t(size_t, size, ALIGN(dest, 8) - dest);
memcpy((void *) dest, (void *) source, len);
clean_cache_range((void *) dest, len);
--
2.35.1
next prev parent reply other threads:[~2022-04-26 19:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-26 19:02 [PATCH AUTOSEL 5.10 1/9] ASoC: Intel: soc-acpi: correct device endpoints for max98373 Sasha Levin
2022-04-26 19:02 ` [PATCH AUTOSEL 5.10 2/9] ASoC: wm8731: Disable the regulator when probing fails Sasha Levin
2022-04-26 19:02 ` [PATCH AUTOSEL 5.10 3/9] ext4: fix bug_on in start_this_handle during umount filesystem Sasha Levin
2022-04-26 19:02 ` [PATCH AUTOSEL 5.10 4/9] ip6_gre: Avoid updating tunnel->tun_hlen in __gre6_xmit() Sasha Levin
2022-04-26 19:02 ` Sasha Levin [this message]
2022-04-26 19:02 ` [PATCH AUTOSEL 5.10 6/9] cifs: destage any unwritten data to the server before calling copychunk_write Sasha Levin
2022-04-26 19:02 ` [PATCH AUTOSEL 5.10 7/9] drivers: net: hippi: Fix deadlock in rr_close() Sasha Levin
2022-04-26 19:02 ` [PATCH AUTOSEL 5.10 8/9] powerpc/perf: Fix 32bit compile Sasha Levin
2022-04-26 19:02 ` [PATCH AUTOSEL 5.10 9/9] ata: pata_marvell: Check the 'bmdma_addr' beforing reading Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220426190232.2351606-5-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mpatocka@redhat.com \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox