Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4589619iob; Sun, 8 May 2022 18:25:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4Ypo8PHVYe8lSNOB+ZuJK7kMNRmafSBSnMZZi0ZOqliLqDzY5A/uLqB0U99PJK4iO6koP X-Received: by 2002:a17:903:1051:b0:15c:f02f:cd0e with SMTP id f17-20020a170903105100b0015cf02fcd0emr14039717plc.81.1652059525520; Sun, 08 May 2022 18:25:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652059525; cv=none; d=google.com; s=arc-20160816; b=VI8vEkcXiFmjkFPz3/Lg3IR3TXRgy/mzB5Xq2im+4mrJZB9n4OCB0izd3zJCNEMg26 yHqYrfAF4T1xi/DtyIAF6VU1x6KBlpAPjqqdciHAnrCNQonTa+ZiTJkX1b3/toH1OvTz MCVydQG64qsUTYfE+egJqYucHYP0+lH/MBWqG5hR107c7D5xvWNWZNlB1H46dGj9GnQC QUxhhAIIoV2efprpf4OxTdqWhz1T7bU3R5NSS9RAeyV8OHmv3KoLcqXESqGVev1dUlbF NqNvxufJ1A7ciL5vCgLRsJTzDDnpT7o8iTrI7C4WAQKTechI6aXir/3FOdD8Nqecr78W sX8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pQI+laEASNHlTCgft4pOvU9w2pqoTmIyUsFhYhgUQM0=; b=LX0wGUJqQkc3ils8PKg+dJ/OSikit2nP7G7uYQuKWeYKEnVny7tUcduoxJrqKia/vf WlehPnaU1Vtq1NtGdhFPFHl99hmL5YN/SCDzH4/M+enqa76GMxdnq/12q1LcXuMNJ71q l+Il3NbZvQDRJaKrB3bjYj7U760A4ei8XyXeBLxOeBbh4+dDCuVGzEbBFLTr+OjQZqw5 Ku7acEVudcbIg0fQQX4bihtT4JpEA5YywK5nQ+U4PHWVr2gK2Pzgd8PfU2RLPAmx2OTJ SJ+7Tz4gInunzAUosHZopixKLT79JGIGOJ+nFATKCXKGdmyy+GZ3JiRFfRN05RiTZSSy ZvyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I31QLYed; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id ob3-20020a17090b390300b001dc4eff067asi21547607pjb.91.2022.05.08.18.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 18:25:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I31QLYed; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4FE9A14000; Sun, 8 May 2022 18:25:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355676AbiEDRIg (ORCPT + 99 others); Wed, 4 May 2022 13:08:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355659AbiEDRAT (ORCPT ); Wed, 4 May 2022 13:00:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50D924BBAE; Wed, 4 May 2022 09:52:00 -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 dfw.source.kernel.org (Postfix) with ESMTPS id C03A0617BE; Wed, 4 May 2022 16:51:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E884C385A5; Wed, 4 May 2022 16:51:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683110; bh=aEDMA/3oe/qWVXNiG9wL+UoIZG5uPLMm54IzJ4kwM5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I31QLYedeNZ9Gwj7V3HEvdclL1C14PmmHal3te25aNJlugBiCF7iFeNAoSk7K7sa1 SnoaNX0v/qL3xciRGYFt3Qz+x6a1jXA2woEkidqZlDNwf+gUZM6YUbwNEb5BF12WHu oSwM1rvVRR3msxaWqVT9nkhXwDelZz78roV+583U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Linus Torvalds , Sasha Levin Subject: [PATCH 5.10 102/129] x86: __memcpy_flushcache: fix wrong alignment if size > 2^32 Date: Wed, 4 May 2022 18:44:54 +0200 Message-Id: <20220504153029.038791063@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153021.299025455@linuxfoundation.org> References: <20220504153021.299025455@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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