Received: by 10.223.185.116 with SMTP id b49csp3487802wrg; Mon, 26 Feb 2018 00:23:30 -0800 (PST) X-Google-Smtp-Source: AH8x227Qcpuzfophu1L1GQIMVo0Fu4/V8lKtZ4IBiXa4frOoO4UeX/7zyijlfc4g4gQfaKwvXH6/ X-Received: by 10.99.124.68 with SMTP id l4mr7771275pgn.225.1519633410517; Mon, 26 Feb 2018 00:23:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633410; cv=none; d=google.com; s=arc-20160816; b=ppFfNCtdRmT+CcZkxvLlc/54R91glqGqFoNdKBrBryGGU23lfgl8MX32jxMJZCM6+y IYbFGGuy9yHVlSJU6ovJClOi8Dl5QUCFK/pCOCatd0PBTrZLEIX8gmkKWgzFqmYHLn2m W6ZW2zjkdxIXl3psdluF4qtgzbl5XVHl5NrIg056Q+QEoR85ERw/RlPe4q+x2famVEhK EvJ9m7WKYXaxlHwSOjauU1e9nK35I3OaSvp6X5XBet5nWHb3m7ZpQIdaD5kYURZIHImx WFz/5vtWxjQ2PaYnub7ePFdqHiSR9ZDand7ioWgJ34yba7uBUgjbBdfbFdZVvcGEcbjP TXKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=faQj8JqC4/KwGNZMuLXKQ1k5PdvnOQTh5XG4tCkdUZY=; b=KnH4LJL5dQIVe0AplOqg2lO/5YzJsBk5bgxg5LJVktlSNvc5z4mmHC4EImfhIqienY 3CPnvFkQGzjhHDHT/Nfge9N7f/0dZao0yHzsklHrFV/No3M/pfnqPWts8gHHw2f1xQnr DpKkL81+5VwsMfpR+5NgmJhksvt2LgkdSDgY/+DI+Yac7yVca8WyMYiJc5G519b5CuH8 Sn1nozAy35v2WCR+AdNlj0sNufKq/K/jZcc18qLKqReDEZ0HusHz0vCgWzP2xq/fyn3F y4+D+AIt0hZ6QIcR3eP0XLPbqnrLFfGUrimCDLaZcu1HrJlDCIqFLDFOgwyDmJ9rEXxR YEFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CnxY6PLp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e17si5233482pgo.61.2018.02.26.00.23.16; Mon, 26 Feb 2018 00:23:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CnxY6PLp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752376AbeBZIWI (ORCPT + 99 others); Mon, 26 Feb 2018 03:22:08 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:45434 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752331AbeBZIWF (ORCPT ); Mon, 26 Feb 2018 03:22:05 -0500 Received: by mail-pf0-f194.google.com with SMTP id j24so6215839pff.12 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=ZoA/n831DmEIOGKy4+zgJ9UM+qiATThyR+bih97acFMtgS8e9+dFJA0+Cik6h8Bw9C yIVcHcfp+sNu3Tx+kUJo9R65WspvpYgUXDGBKBCO0L7VEjOrJU61Gm0fDplc0RThqtZ6 PKSjzG7tSbCYI0SwQ3sU1kkRex1ug+8aCV6VLpaS5SKBa7nRmHz7mZXUuJ4Ooqig+4Jg Kgq4CEy3KSBN+DWDFUmdfLhO7VFQ1WD8gBp06FN4TNhq5OH2GADsxrG//A6XQa9w0jGu RCGWZGMkMhZ3txrix0Y5gNY9dp+NGeZ5sPwW5mhXAnIQGXDmyUSUGutSD2dy9AsDCBPR z5VA== X-Gm-Message-State: APf1xPBo77zbxi0HxGIw0vVz9SmCZn7EC5RtZ73k92u9EfHvXsUqcqNW jKk/VJzGOZ5mDsgnCTWNrsNnDw== 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) Cc: Mark Rutland 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.7.4