Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4603240iob; Sun, 8 May 2022 18:54:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWUAm25kxPgcCEqTAcdS7zoySSDmRRBvMGsmaDINksvjqiHhl3sOfxT8MMOhA/g94GvkvH X-Received: by 2002:a17:90a:6c43:b0:1dc:d03b:5637 with SMTP id x61-20020a17090a6c4300b001dcd03b5637mr17872296pjj.15.1652061277795; Sun, 08 May 2022 18:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652061277; cv=none; d=google.com; s=arc-20160816; b=IS416LfoCJFmOSJYYHqHadniiX/qxnwHnSa665BvZLJeeXtcSvZtnMZtQbqjW1yr/x 9qirhlqbUigwk92E7gdq0Byr0j6zyxbe6WzDWZ0zoBhn32zJBLm43VnCHEhHh9ugmWlD 7SI+NZm05kN5UUN4xC/7hfjnuAJ91IcVi8BgghbSO+jdwCL1sKu6H/hQjAGBjyn/6aNm HSfZ+SAIz8xFAPhhqonD72ohzDLqGu/2uS/lrQARG/wsBQFtLuTUFd8xhU7xugugrO/H M/6xT9I0uErO+NQgE4++tZ0XqKsIbtx4zpGhk8gCxEsA3crOlUEBnRwTzN++O86nybh9 gXaQ== 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=6dCFK6Dg+JLvXzi/kFSIvN9myZWzpQyQYRPh1N7YB08=; b=o+BVDpiQU8lr0xQvKhnerXYoX/XCnMxnsqZzrOIJuoIkUIXR7GlAs4RAg5TRvxQkUD lfeY28zsxd1e8N/RuVyKo/YVMAUI97AdEnOok/pl1ze1K3Dt4saW/2G3j8YkkmX+TYYB XNPNrHTfQ0o3oxlxkC/XyKDzVQw71HZ5UKzuzVEPF7NhPUnMBZCjQs90eV8in8nsvBcg E5sVpAfy06yWch6yQc1JJ4Of1jSN6+mNcsLFojFYKYL9rN/414WCuapR7lhun21R0/8Q gyPsi7tKlZKs6kzRmuK6Y2ZoaH3ShqjVG1CmwdgAzoEAPvNDt95iAfG+o5xAHt6mLl7p hKmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=itxNc3uT; 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 n8-20020a170902d2c800b0015d56a3c9d0si11493175plc.534.2022.05.08.18.54.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 18:54:37 -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=itxNc3uT; 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 CAA2F433B0; Sun, 8 May 2022 18:54:29 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354010AbiEDQ4O (ORCPT + 99 others); Wed, 4 May 2022 12:56:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354191AbiEDQxz (ORCPT ); Wed, 4 May 2022 12:53:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D2D8483B1; Wed, 4 May 2022 09:49:12 -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 6337F61771; Wed, 4 May 2022 16:49:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1B14C385A4; Wed, 4 May 2022 16:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651682951; bh=IwX2/NnejUzN7u8g7KsKfNNxuvUqvIN8hWL1MrCgCGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=itxNc3uTTXStJ4b5JIlC1tA0vv037DbE0zngd+S7cgM4Y198nVR5AJjQpO7+SG+Zg He591syb8p9nHFmFc2LWL/sKuFgzhIxsWyL6qA2Us1DrP/jqDW8eaaKXQEwm0ZhFj5 Umedf7b98KLm6K/9s7LK+NTQUq3xm2qxB0qV1+gE= 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.4 70/84] x86: __memcpy_flushcache: fix wrong alignment if size > 2^32 Date: Wed, 4 May 2022 18:44:51 +0200 Message-Id: <20220504152932.925204395@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504152927.744120418@linuxfoundation.org> References: <20220504152927.744120418@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 1847e993ac63..f3f7f4cb15a6 100644 --- a/arch/x86/lib/usercopy_64.c +++ b/arch/x86/lib/usercopy_64.c @@ -142,7 +142,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