From patchwork Mon Feb 26 08:19:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10241455 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 B6145602DC for ; Mon, 26 Feb 2018 08:25:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EB8429D8C for ; Mon, 26 Feb 2018 08:25:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 937C229D97; Mon, 26 Feb 2018 08:25:16 +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 293BE29D9D for ; Mon, 26 Feb 2018 08:25:15 +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=u0B/HPxM9LV7sk951guuolgaSe ElvMh2jBLQtOIGzOqNsgy1nVrcZSnCv3RggLMvpMKX29/3Tj/2p8vkDshQlmSdlPcxGle7COC2VAs oCP+Pf+F8QQ6/AU1CNsgQ7gts2akqSvfN545wBsklxQUyqQC2Fj46wnBe7gkyuO9Nmwev80tayetd RrXk1oe7om9IIYR4/8fPTSv5FZzAOf3PXGVnQ0sw2444En5PQ2MhJEjxccYksEW63tAYmC0D5Eqa3 3H9QVmWfzAWnePBZYxJmvHvfcWDeuy7hi26n3x0yGRrczkwmulw+Fm1dg//gmuYiPFVeE2tpDsx0v 4SKvFOQw==; 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 1eqE5n-0002ZX-Si; Mon, 26 Feb 2018 08:25:03 +0000 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqE2z-0000aW-Lf for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2018 08:22:12 +0000 Received: by mail-pf0-x243.google.com with SMTP id a16so394610pfn.9 for ; Mon, 26 Feb 2018 00:22:05 -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=CnxY6PLpkO4tHJqWj2rQ4/NjiX0Nxnxgf9etNtMJ9uCyXyiUYyrXV1usAmq5stT+dA OmpMx/YgVPBIXIGZg7MmF92x2zdDLRN64ErpGZmyl5veaYxaGn/vE80bXQzlzqIVdz3z c+Q+qT/H9t+zRZKd0Vln9N3uqdhAAHsb3nXuE= 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=QfwMtXuXr7/kAXHM4mcwG8yMUuSLuYsAhYYSdBlAMHNI6QcP57yXzKreI7N6r+QHeU c9xeSS8IGHUzKPZcFIoMS7EgWiT22EkMQdJ8dV1iRwqZupTyNFrywgfnQL/8t49VRdHW hDZVXdajD9Y/lePhqtZH3dhN5XaNkvtOmPPUCZDjUAcaH9jvP/qxeHVsy7Pap4mvZK8L l0tmBxxyAYXjnmkTV+5+aHXYS/ZR16AhrC2TEsFzDbtbtXqXZJWBvPWTHZtu6X/jyUGb 4Es0x630Ys+319KnHu3ysfKb+y8ICw1EwgWTB2YeqruhuPjnmWF8S7vXrCZPxw/FozCw ftOw== X-Gm-Message-State: APf1xPCBzKCBUqVEPHerckfrXsJbxRKfOXu41J55NDMUyN6ZfEeckMC4 +6gHeqZ/NhtQvkrItvkKvj6i9Q== X-Google-Smtp-Source: AH8x226ig7va8Q7SqruxsirHNdmRS9mlMzgRBRV5ZOxfTYyNvwFj1p6Hbpat3wfsr6BDCSvGl9f1Mw== X-Received: by 10.99.4.197 with SMTP id 188mr7595547pge.359.1519633325303; Mon, 26 Feb 2018 00:22:05 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id o86sm1422706pfi.87.2018.02.26.00.21.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:22:04 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org (moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 08/52] arm64: uaccess: consistently check object sizes Date: Mon, 26 Feb 2018 16:19:42 +0800 Message-Id: <1519633227-29832-9-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> References: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180226_002209_967005_10DFB647 X-CRM114-Status: GOOD ( 13.90 ) 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 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;