From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98DF6C433EF for ; Tue, 26 Apr 2022 19:04:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351830AbiDZTHQ (ORCPT ); Tue, 26 Apr 2022 15:07:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353743AbiDZTFk (ORCPT ); Tue, 26 Apr 2022 15:05:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A45E19983D; Tue, 26 Apr 2022 12:02:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E1A79B8224F; Tue, 26 Apr 2022 19:02:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85FACC385A4; Tue, 26 Apr 2022 19:02:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650999745; bh=aEDMA/3oe/qWVXNiG9wL+UoIZG5uPLMm54IzJ4kwM5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZIwc0igcO5PA+8R3c9mUICZEi+bYBHFT0IumQz4PY2HTxa4io2l8EGklo8NyNa69L D6sk1nqXBNyP8VrLddqeZ8wPhsPjG/Lj9kn854dUM8yEchvY3d0g11BVtGgMMED7m3 GZc33OhJUeTAtBaNqyDahptAqk1KvMmeKMqAsFxSAbQ9srGth3x+oVBvPFAfDBRiXZ ZwRIvpuVmT0fL2eQqX3ed2x6otVS7M246g+DZI+z3gGKg1iDz9x2C0tZJbPXRTKy5H 5XMeqjylV2GLKoxhXUDBnvGCrZAUx42JgkmjCfJ4Z9mJhQf6un+z16T3A6EJ0c23ur ISQf1vTAy4rmw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mikulas Patocka , Linus Torvalds , Sasha Levin , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, jpoimboe@redhat.com, peterz@infradead.org Subject: [PATCH AUTOSEL 5.15 09/15] x86: __memcpy_flushcache: fix wrong alignment if size > 2^32 Date: Tue, 26 Apr 2022 15:02:08 -0400 Message-Id: <20220426190216.2351413-9-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220426190216.2351413-1-sashal@kernel.org> References: <20220426190216.2351413-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mikulas Patocka [ 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 Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- 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