Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3706563ybz; Mon, 27 Apr 2020 21:55:57 -0700 (PDT) X-Google-Smtp-Source: APiQypIEHfAywn/dlDKOBFo0doD3a4ODnfsVRf1drPtAs6kxj9T+ks6boneEixltG/M7VXn3yptW X-Received: by 2002:aa7:d794:: with SMTP id s20mr22345652edq.141.1588049756743; Mon, 27 Apr 2020 21:55:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588049756; cv=none; d=google.com; s=arc-20160816; b=QtV043d2YZ3s1M1OAPAC3iWCsWmOV2kw0dL4tNXGGolJi3WBT1xZdfj4ahDNyMsQf6 bmaNEQ+pP6k6oxbF0Grgk+cRlHzQ8wfWtPs4xjtagh722sfOvhQtzTTsQzKVpmoyVWr6 eD74FXr6/kIbWAWMHoaelcoVbv6o6Pr1cGUx8MM9OY+XkyoisuljCEsr3m9QEeWxEUjq Gqn6SQC0e9fHx2hwWOEwIvCu9t12XSEsbg5EJ5iY4xD6fKbGtPOtLUIilZU/9kxxqsLB RW0QXx4WpFiLMHTJyPigBEb42lKmHQL3zXhEntLUJeAq8vIQDU8wCMtDJaInf8EV2VFE +jqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=JrjPs69r0pUjI4jiWO1HZG/wjkxDutGKz6XBMDQZWzU=; b=E0KYPL76lAVAjRTgLhYT/A/js9oWL5vuxGfOVyXOuoQ5BGSDKvf2QAvgTiKdVQmmSn nkGPHZ9ROLpCw3EqDyPWPwkKW5stH36Zg7Q/uvjSBGJQ6QzCJb26Q63/Py10SljOKs7u cxZw2yd4rW28NpYgQZmyy7SDhfcOZ6EpwkKNmhjW83xEG+Z63C+O+n0YOLdQua8vIhSR bc1INSpwURkmXj/evWxSoSwF+xr0OFPBu0ltNfDy3YBd5tl/KL2LpmT10V0gu3YqR2jS TivYuTJ/G/M9zttEHlnx+E0oBf/0KDPXLV4Brv+VmUeJ1ubiZFGIQAroUPCnML78gkWX pfAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Sp3Ct+QA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id i8si1075699edy.253.2020.04.27.21.55.32; Mon, 27 Apr 2020 21:55:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Sp3Ct+QA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726276AbgD1EyF (ORCPT + 99 others); Tue, 28 Apr 2020 00:54:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726271AbgD1EyF (ORCPT ); Tue, 28 Apr 2020 00:54:05 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8842C03C1A9 for ; Mon, 27 Apr 2020 21:54:04 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id y4so20036668ljn.7 for ; Mon, 27 Apr 2020 21:54:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=JrjPs69r0pUjI4jiWO1HZG/wjkxDutGKz6XBMDQZWzU=; b=Sp3Ct+QAOIYkMPPYb8+ZTX2eAupbevFH6R2qOF98spZhleatVY1QJ5fLuRlronmMwm eJ5uID4NlgC2K5EJYj0qrbJxoTPTQKcdjYYvdjVM/y6H2WizHrMJe8S1E1MF8Y58vO3s T1xbs9g1wJQzLFypE/CfhPnRqv/Pf0uOEy2+KHxGgbd39auv0h/4PNzRvdnufjCCbHiV BeXfi54GotFuMkpPxVuR2OMEosQMNPsT7Dpc97ow21KbWQxB2FxXyP5fkZ+Tvuhi8iuJ gLCExSq86j5Mt6FIzLYexOxgcZx7LJnWqRrJwgU9+I6UgTRT7ukVrTpeOv4N5XWSKsR9 Pjug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=JrjPs69r0pUjI4jiWO1HZG/wjkxDutGKz6XBMDQZWzU=; b=s17u9h5QS3jI5w2EKj0fAgZenzwuR5E2B5zQcmt3hIKRtCkN1JObE+CUu2CM9YYGWq XScKpEccLbevVVstyYq59X8m5XWjRgRXLUa0F4mQ6aVaiWz1hpX35sOadEFJYuVVAb8k 8/dpOE62RZjWjfsN/kqi3zOYuDCU7ML4Bq4tEINNf4SOU/t8fjaPC2ZwbA46T4zHYQan GvNhdQ/hK5beoOBgT+eWpFdR311ksREu0W0don9x1Jy1elt+m8eiFES8IDygVJvMlJDd Biz6HHDgd+EE6yvEdPYuJdqAJOjQhcdvtGpwI2wq1DbfACJxiUCDg96/g3oK1SOK+3/F 3+Dg== X-Gm-Message-State: AGi0PuaofsxiyO2fXviES7SkpGj6dWN8XDTtJOrO4sKdzLVdo/eMY4Ze i5ljrg+OsyzdMaUFHhzpvXAj3smucWsy/5XLoJzSvA== X-Received: by 2002:a2e:80da:: with SMTP id r26mr16218619ljg.38.1588049643021; Mon, 27 Apr 2020 21:54:03 -0700 (PDT) MIME-Version: 1.0 References: <20200418144047.9013-1-sashal@kernel.org> <20200418144047.9013-38-sashal@kernel.org> In-Reply-To: <20200418144047.9013-38-sashal@kernel.org> From: Naresh Kamboju Date: Tue, 28 Apr 2020 10:23:51 +0530 Message-ID: Subject: Re: [PATCH AUTOSEL 5.4 38/78] nvme: fix compat address handling in several ioctls To: Sasha Levin , Nick Bowler Cc: open list , linux- stable , Christoph Hellwig , linux-nvme@lists.infradead.org, lkft-triage@lists.linaro.org, Basil Eljuse Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 18 Apr 2020 at 20:24, Sasha Levin wrote: > > From: Nick Bowler > > [ Upstream commit c95b708d5fa65b4e51f088ee077d127fd5a57b70 ] > > On a 32-bit kernel, the upper bits of userspace addresses passed via > various ioctls are silently ignored by the nvme driver. > > However on a 64-bit kernel running a compat task, these upper bits are > not ignored and are in fact required to be zero for the ioctls to work. > > Unfortunately, this difference matters. 32-bit smartctl submits the > NVME_IOCTL_ADMIN_CMD ioctl with garbage in these upper bits because it > seems the pointer value it puts into the nvme_passthru_cmd structure is > sign extended. This works fine on 32-bit kernels but fails on a 64-bit > one because (at least on my setup) the addresses smartctl uses are > consistently above 2G. For example: > > # smartctl -x /dev/nvme0n1 > smartctl 7.1 2019-12-30 r5022 [x86_64-linux-5.5.11] (local build) > Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools= .org > > Read NVMe Identify Controller failed: NVME_IOCTL_ADMIN_CMD: Bad address > > Since changing 32-bit kernels to actually check all of the submitted > address bits now would break existing userspace, this patch fixes the > compat problem by explicitly zeroing the upper bits in the compat case. > This enables 32-bit smartctl to work on a 64-bit kernel. > > Signed-off-by: Nick Bowler > Signed-off-by: Christoph Hellwig > Signed-off-by: Sasha Levin > --- > drivers/nvme/host/core.c | 27 ++++++++++++++++++++------- > 1 file changed, 20 insertions(+), 7 deletions(-) > > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c > index b8fe42f4b3c5b..f97c48fd3edae 100644 > --- a/drivers/nvme/host/core.c > +++ b/drivers/nvme/host/core.c > @@ -6,6 +6,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -1244,6 +1245,18 @@ static void nvme_enable_aen(struct nvme_ctrl *ctrl= ) > queue_work(nvme_wq, &ctrl->async_event_work); > } > > +/* > + * Convert integer values from ioctl structures to user pointers, silent= ly > + * ignoring the upper bits in the compat case to match behaviour of 32-b= it > + * kernels. > + */ > +static void __user *nvme_to_user_ptr(uintptr_t ptrval) > +{ > + if (in_compat_syscall()) > + ptrval =3D (compat_uptr_t)ptrval; arm64 make modules failed while building with an extra kernel config. CONFIG_ARM64_64K_PAGES=3Dy # make -sk KBUILD_BUILD_USER=3DTuxBuild -C/linux -j16 ARCH=3Darm64 CROSS_COMPILE=3Daarch64-linux-gnu- HOSTCC=3Dgcc CC=3D"sccache aarch64-linux-gnu-gcc" O=3Dbuild modules 70 # 71 ../drivers/nvme/host/core.c: In function =E2=80=98nvme_to_user_ptr=E2=80= =99: 72 ../drivers/nvme/host/core.c:1256:13: error: =E2=80=98compat_uptr_t=E2=80= =99 undeclared (first use in this function); did you mean =E2=80=98compat_time_= t=E2=80=99? 73 1256 | ptrval =3D (compat_uptr_t)ptrval; 74 | ^~~~~~~~~~~~~ 75 | compat_time_t 76 ../drivers/nvme/host/core.c:1256:13: note: each undeclared identifier is reported only once for each function it appears in 77 ../drivers/nvme/host/core.c:1256:27: error: expected =E2=80=98;=E2=80=99= before =E2=80=98ptrval=E2=80=99 78 1256 | ptrval =3D (compat_uptr_t)ptrval; 79 | ^~~~~~ 80 | ; 81 make[4]: *** [../scripts/Makefile.build:266: drivers/nvme/host/core.o] Error 1 full build log, https://gitlab.com/Linaro/lkft/kernel-runs/-/jobs/528723851 Kernel config: https://builds.tuxbuild.com/DeL6EepmdRw6OaOGmg7F_g/kernel.config