Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp513982ybz; Fri, 17 Apr 2020 05:25:10 -0700 (PDT) X-Google-Smtp-Source: APiQypI9Sc7Oqru4aecNFYJ3vl3VxIWuiFkglVeuWYbFfbzYLjGeoSZdcS2CZdnebrCyi3sCQNg2 X-Received: by 2002:a05:6402:154:: with SMTP id s20mr2756746edu.224.1587126310217; Fri, 17 Apr 2020 05:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587126310; cv=none; d=google.com; s=arc-20160816; b=d1hqGVazWe0y5aKS70uopG+YCTAQrtNkgeGa6iZr18OoncyGmamY1HP5q/S/xikRMA iMFC1F1n8537f7Pz9T6IwClPX3bHsIV7PURFm4Hsbf1Auo5R3TUkILVoWeo8eWZRoEpL Hv6m8f4Pbl6EVzn8m6MS+mBNkBF+ZPdL4MkXKira8WJmqRGepUp1AAUmOZdkbqQwmqfK JYfmsG0kV4+SPesjuvlva3akYBHGzFPNkyyk3m/3MrPVAvWz6WH+l3o0YGSj4j0BWXuS b4/ehdQyQAKWZV2UETb1aDZ969FE508pkx49isBbRz3FBW/4CDVdvZma48UpEvZR8NrP p35Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature; bh=/XhlNj1iT3WQkhADr9/4kLmHqtW9qmgUZNuTtPEyYis=; b=U1gYbyj9ogrVvia0efGlPbIIVOlcIJgZ7wUBNM50Od3f8H/BYANTOtJ87b/yCTCRs7 BwJNcmJo29JBmuRpjwiL9QDW8bsArcHiBgBTRR9konh89K8cbU4m1Y3OadttzDKfksgn 2UDuMGN56fcRTOd7Fk5xDpnlmTuF5P4qvIlSPXUNNGWgVn0jRiJje/Qa8d2s1D0ASnRC yzyeUN5Q3IOsEMRdbGLdeiPyqxWCzhDFavzMtTjZnPre7eHPBMnQd9G1WaAOtkot7RSC LEBMK8vXlol5SMJHKu6ax3Jp7U43zcxok8Pwszl4est+/DZqhbBDKqbsd6Dua92aIIVS MTwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aE88IKY6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h9si15328311ejt.130.2020.04.17.05.24.46; Fri, 17 Apr 2020 05:25:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aE88IKY6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728856AbgDQMVf (ORCPT + 99 others); Fri, 17 Apr 2020 08:21:35 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:50524 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727877AbgDQMVf (ORCPT ); Fri, 17 Apr 2020 08:21:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587126093; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=/XhlNj1iT3WQkhADr9/4kLmHqtW9qmgUZNuTtPEyYis=; b=aE88IKY6GHInf7bYM+L7C+bndRlemi2FAtAgWiUwLiRTnOANC8gvER7ImJ4bJ0i1leUJkh 1/9KzMYpLvjIU+GbYYctll8T8zOmj/COJXY79x+vYyQNp5SsWn0D/KmWQwdNa3UCEmooyA LGml3LA15yYHjcCokQWW4bdnwnETUTA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-494-DTJz6NcoNpKi8yYM_qEdIQ-1; Fri, 17 Apr 2020 08:21:32 -0400 X-MC-Unique: DTJz6NcoNpKi8yYM_qEdIQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 76E848017FE; Fri, 17 Apr 2020 12:21:30 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 208BA11A08D; Fri, 17 Apr 2020 12:21:29 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id 03HCLTqV032105; Fri, 17 Apr 2020 08:21:29 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id 03HCLSmY032101; Fri, 17 Apr 2020 08:21:28 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Fri, 17 Apr 2020 08:21:28 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Dan Williams , Thomas Gleixner , Ingo Molnar , Borislav Petkov cc: "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] x86: __memcpy_flushcache: fix wrong alignment if size > 2^32 Message-ID: User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The statement "min_t(unsigned, size, ALIGN(dest, 8) - dest);" casts both arguments to unsigned int and selects the smaller one. However, if the size is larger than 2^32, the truncation returns incorrect result. For example: 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 --- arch/x86/lib/usercopy_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Index: linux-2.6/arch/x86/lib/usercopy_64.c =================================================================== --- linux-2.6.orig/arch/x86/lib/usercopy_64.c 2020-04-17 14:06:32.039999000 +0200 +++ linux-2.6/arch/x86/lib/usercopy_64.c 2020-04-17 14:06:32.039999000 +0200 @@ -141,7 +141,7 @@ void __memcpy_flushcache(void *_dst, con /* 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);