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: 130188 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp2761108edc; Thu, 1 Mar 2018 04:56:22 -0800 (PST) X-Google-Smtp-Source: AG47ELvCxmkbTQIAcN08jAm1h+DXvKS1e46NkVsWhECnyUoB7kW7XbkzWv+AcOli+51Eb6YEtDlt X-Received: by 10.98.171.24 with SMTP id p24mr1852406pff.71.1519908982765; Thu, 01 Mar 2018 04:56:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519908982; cv=none; d=google.com; s=arc-20160816; b=Qd7eHI1WofFuxBv2WBBqvUPEecXnxM21R7ogiDC/TA5zy54TnS2AVX03o6wzdWSGSz WjBGYKECvLUP+z7OLr1zebdIdwvq2sWP59cKPfB29TKQ46zWUc3PK9USzVCIGtKuX0SL kpobUkOC7q2bvS0OUMBlRJUIi8p9ScJ3BxpnQZAMf+McnB1WfuGsVauF3qySYQgCuZgt bZG3CPWRL8nPMWwlYl+P2LgJDcFK+yefsJgdd1XhOlgc8gEAXMa670zz7oNI514fixJV fX6RyX3yBMQIp7Pb57afTxIEhV7PcRL4xTUBYuXk+pzwIrj946JKqo8NWJVomhJ5wa96 d+0Q== 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=fRR+fi6vDrrrRG/mXh9hiRouLK7GfuG9ys5ndMA3MdZNOlOZUph0Nbg63mgFSpkndQ QJhTMxXiuVcYsJkdCSwLuZyPmf5wq5dvOReYEw01XGqjrjYGMe3A220V+D+hSu3TuIH0 p8WO4cyIWXUx4t+vwOqnHF2v1xVFNejyXfSZrVm0GwfRzCHSAG8O7xUy+VQXsjwi874X JYkRsHUSiy1zESmBRBN9JJmWUFJtBfvd/96s0DniGc2Ywf9A+GAhQqbNxyisQa0Uv1GO 1gZUv9tey3UyDLeuu17/avXFsPel66OlkPqmWLcppgsx7uMmTXn7ibJ6f0cDMZAMKZxs zd1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VwStRMao; 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 v17si2956195pfe.186.2018.03.01.04.56.22; Thu, 01 Mar 2018 04:56:22 -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=VwStRMao; 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 S1030709AbeCAM4S (ORCPT + 28 others); Thu, 1 Mar 2018 07:56:18 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:43108 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030578AbeCAM4O (ORCPT ); Thu, 1 Mar 2018 07:56:14 -0500 Received: by mail-pl0-f68.google.com with SMTP id f23-v6so3582541plr.10 for ; Thu, 01 Mar 2018 04:56:14 -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=mv0D34gwtCNQ8vr5YUfWa2ZH5Jn6kfwwt0YGxPeq0pzak9cukMtBPqFAcHhm5Q9qGD 4vzaRC6ykisYyBl5PsO3bAF9CsObTrmAjMFKjlHQFsyGvwIP/fNRzWqDZWgL2VrHyWrb bfl/PGC9kRKueDwSICBaU9ZufX1eVO9zEseij/3ocGrep0QL3qNfdpJPv+UhVPALlgQG 5Lim1ZGJDOEPLHAuk3yW+qBUvRu+uT2b2AnwzK52o2TtsQIcx6l8WXSNOQLIeAaDPWta PAAptiTdCQqHDVRGokEjVtbmEUkcLuSDgmINUZPLg8c67WY4FfxpGWUWoomsXs7Rm9jW IuEg== X-Gm-Message-State: APf1xPAgnb89zLtxrGqacKoenY1j7MU4GNDMYThEsILf3FTaF04RjyjI EVsSGJkKYndfILTbyNhpfCk9wA== 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 Cc: Mark Rutland , Alex Shi 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> 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(-) -- 2.7.4 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;