From patchwork Thu Mar 1 12:53:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10251367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A4368602B5 for ; Thu, 1 Mar 2018 13:26:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92D5F1FFFF for ; Thu, 1 Mar 2018 13:26:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 863822015F; Thu, 1 Mar 2018 13:26:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 56E321FFFF for ; Thu, 1 Mar 2018 13:26:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=DuJcU0iwx3xuPe3O44w15zFkh+meDzDgByFLXTI/Vgw=; b=p5lb8Hu5+j9yAAayuIeQTqprlB gz8ORSFXsx3djLAgrrYOP4ZqNep9fqa9Jxq/IemHhHkDYs42qaxG3WLeYygr/O20k8RXoyq021/RQ wJ7E7dkuRdmd5A/jw8Dc8iixv2P4q2kXobO2o9Ann8W9u1SeI+RmiiHOjFomKxj1BoFZCIzyn16V7 CCxUGs1STDCbPHUV+srQ87z9u66owjJ1MP7jhdfTLU69yOfFw8IgMuOAwL9HPiuMmg7vKP/uDkmVx 5CCrG8jbVcmZ1cUdUjrrMTGGFQK1RE5lgoEB/NM9cdjDsMze0rqiZ/LUXmJm6cE0RaOD3Tlr0i6Rn TrBqS6dw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1erODm-0008Bm-7M; Thu, 01 Mar 2018 13:26:06 +0000 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erNl3-0000qT-FK for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 12:57:50 +0000 Received: by mail-pl0-x241.google.com with SMTP id k8-v6so3579732pli.8 for ; Thu, 01 Mar 2018 04:56:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=faQj8JqC4/KwGNZMuLXKQ1k5PdvnOQTh5XG4tCkdUZY=; b=VwStRMaoDqp7alKKuHhPa/i2UlOlBpXVz03G+MB0JFEB9uQOWyfUMOW9ERCIBMMf1v HJ9vUCLKrPJHtgFA1H6fxNoUV1/dTPWaX9JYCRHo0F8dZOLndhMOK+uqDP/dOc0/Ssez Eb7ZCCCV9r9VdZXGQCOOta58FxQWBWGTAejpE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=faQj8JqC4/KwGNZMuLXKQ1k5PdvnOQTh5XG4tCkdUZY=; b=liYeK+nVgQ+YDkq2Wd/Jm3M1SY8JRNSjv4BF68noTCdg30B1FqQ7Ay9eAh+kgks6Zd g3vWtWC9um35qwQ5/UnCCevUmVJcPnVyBwh5Cdyt2z9YRDsW0SMl0d9eRjJy12iLTK2V UKb6cs+3RaaWJRYB38P1zd2N+RABFt97Qu+NVdGKvFeZWCaS9VH4J1XsR2IKGuByE1ji KgPn97oXuhSk3nRXd+bB5cA99TY20z0wgUycK8ii9kouXdcjn0w+juxfmeyABEHr1c+w bocnWv+RiGMEDalACiXWmfLWUbXlu5C9kvxtgh1c5lI9WnwgHCnUJA+JFsi9wX3YUBtR K/xA== X-Gm-Message-State: APf1xPDvJ1kSAcTPsCwG6msNj7Bt3mRFre0J42QFlY54pXQZao74M/+e 4yKcnohxXLEa9PcYWzKvSf1nkQ== X-Google-Smtp-Source: AG47ELuLyhs09p68iErvWloFIswauoMMbsZquBoT1YJy1IYxPErNDZ/MSS7KrSJM7gcSvAfO3Zb5kg== X-Received: by 2002:a17:902:22f:: with SMTP id 44-v6mr1837181plc.418.1519908974364; Thu, 01 Mar 2018 04:56:14 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.04.56.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:56:13 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/45] arm64: uaccess: consistently check object sizes Date: Thu, 1 Mar 2018 20:53:45 +0800 Message-Id: <1519908862-11425-9-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180301_045626_236045_ED5F52D2 X-CRM114-Status: GOOD ( 14.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Alex Shi MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mark Rutland commit 76624175dca upstream. Currently in arm64's copy_{to,from}_user, we only check the source/destination object size if access_ok() tells us the user access is permissible. However, in copy_from_user() we'll subsequently zero any remainder on the destination object. If we failed the access_ok() check, that applies to the whole object size, which we didn't check. To ensure that we catch that case, this patch hoists check_object_size() to the start of copy_from_user(), matching __copy_from_user() and __copy_to_user(). To make all of our uaccess copy primitives consistent, the same is done to copy_to_user(). Cc: Catalin Marinas Acked-by: Kees Cook Signed-off-by: Mark Rutland Signed-off-by: Will Deacon Signed-off-by: Alex Shi --- arch/arm64/include/asm/uaccess.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 94e1457..09c9b59 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -326,9 +326,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u { unsigned long res = n; kasan_check_write(to, n); + check_object_size(to, n, false); if (access_ok(VERIFY_READ, from, n)) { - check_object_size(to, n, false); res = __arch_copy_from_user(to, from, n); } if (unlikely(res)) @@ -339,9 +339,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n) { kasan_check_read(from, n); + check_object_size(from, n, true); if (access_ok(VERIFY_WRITE, to, n)) { - check_object_size(from, n, true); n = __arch_copy_to_user(to, from, n); } return n;