Received: by 10.223.185.116 with SMTP id b49csp7391797wrg; Thu, 1 Mar 2018 04:57:34 -0800 (PST) X-Google-Smtp-Source: AG47ELvEu/67yXLUXG5262vXRXYkG76SYDovt+5SpN5A8w0R3Oz3AgT/8JxieP4fUwDyzOjP0/mz X-Received: by 10.98.74.140 with SMTP id c12mr1907609pfj.44.1519909054565; Thu, 01 Mar 2018 04:57:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909054; cv=none; d=google.com; s=arc-20160816; b=YzO8hGxuIyzBpvsVVRR6z60AOTjiyzWV553OrSKuPwbkztAgeRXSuh2UxJ2TAsnSri gFwGkjqwnISMKX5frficTpFyXlW7KQl2596Zfs2ItUoD7TJRotpBqvwPBlSoPkctDk1R UPuNw0hyo5VZ9miH1vBZyaQzItbt47NCurV9dVbHRaFVFgUwEAHVG3jNUnYBf+C3ugd8 YqvKuEMkuHsKBUC2HFgF319HyvtFtxXZUNbPkswwbiN9KSA0lF3ikvOMISz/ySxP6bcD 5qsx7ajEOwjEoSaSi2sO8h65gQbH4TWYnRxCYrVMSAgI4cuFKuEENq/GsunLUF/eLKWD GB8Q== 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 11-v6si3008017plc.376.2018.03.01.04.57.19; Thu, 01 Mar 2018 04:57:34 -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 S1030706AbeCAM4S (ORCPT + 99 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(-) 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