Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4332194imj; Tue, 12 Feb 2019 14:03:36 -0800 (PST) X-Google-Smtp-Source: AHgI3IYbKo7XNPBtxn1RuELxC2tSnrHv1bB6izcJIFsDPk0wshE9/sgA9i9XQ4QYNwiCR1Egxp/P X-Received: by 2002:a62:39c5:: with SMTP id u66mr6033904pfj.245.1550009016438; Tue, 12 Feb 2019 14:03:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550009016; cv=none; d=google.com; s=arc-20160816; b=Nym5QzlBMBQDsjgzl5RPlVpjI3l8q4axFkAGJ5xsbjT+VWrkUvE/B+lN+vyH/kXzSI jA+QK9mbN7mgmmzc4ztpFJm1yGLFQSq4yYvPd/H7Kmy7KggokoryJkM84WKk9S0ohZ4T AN7LozZ4q9R49BN7MZSvCwOFnn5JYNBgVapZVkBi4SfYg8OXKHerjDMuvNfgyYdzdK4m 4IrBIzDxZAwLmDPESqM7BG1vNZUUOttud6p5PZm6WOtgF2/lPxKdwcy+LkXPADDt/UzS xSs/Fc1O964ezhrGCowhuiRZxI8pWLw0B4Dk07sxFd7oPZ9nhRctj7/ILwD8uL6MNzT2 KGbQ== 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:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject; bh=DA3i5VeOleh7wIkRuT/BVNtz4Eq/UNAKiFCSpXx6ZGc=; b=twnjW55KJv1L2aIV4prX/evd4wWpqP13mZuLwHtdQkz4oRlJOyWlvyB3aqG527Gxca JCoEP952nfZ1H6J8j85XKYpGxUpo57NLk0cHTg7+/FDMtXqHb66y+87Vqv/4oalfMx31 53q0/zyYKLuGP+sYi4i9wJl7mS99UygAN7Z5L5oVgKnkxwArMvxUPUgnozpst6+w7UZV k8nsCJDAv+4fAyUXOywmAPOVkj2fL3UZBUvwnp4eq0lMRN1Zo6CP43klwWQWvKgtGbje KphseIK3D+itqMM5ZcfIpkwIPc5VnzMKNbAXPURAek0ko+iGDIVleK18mWQlLlPFekrF gK1Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p74si13945958pfa.279.2019.02.12.14.03.20; Tue, 12 Feb 2019 14:03:36 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732589AbfBLVhh (ORCPT + 99 others); Tue, 12 Feb 2019 16:37:37 -0500 Received: from mga09.intel.com ([134.134.136.24]:16717 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732531AbfBLVhf (ORCPT ); Tue, 12 Feb 2019 16:37:35 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2019 13:37:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,362,1544515200"; d="scan'208";a="117400830" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga008.jf.intel.com with ESMTP; 12 Feb 2019 13:37:34 -0800 Subject: [PATCH 3/7] dax: Check the end of the block-device capacity with dax_direct_access() From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Jan Kara , "Darrick J. Wong" , linux-kernel@vger.kernel.org, vishal.l.verma@intel.com, linux-fsdevel@vger.kernel.org Date: Tue, 12 Feb 2019 13:24:56 -0800 Message-ID: <155000669646.348031.16690970886357498896.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <155000668075.348031.9371497273408112600.stgit@dwillia2-desk3.amr.corp.intel.com> References: <155000668075.348031.9371497273408112600.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The checks in __bdev_dax_supported() helped mitigate a potential data corruption bug in the pmem driver's handling of section alignment padding. Strengthen the checks, including checking the end of the range, to validate the dev_pagemap, Xarray entries, and sector-to-pfn translation established for pmem namespaces. Cc: Jan Kara Cc: "Darrick J. Wong" Signed-off-by: Dan Williams --- drivers/dax/super.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/drivers/dax/super.c b/drivers/dax/super.c index 6e928f37d084..a27395cfcec6 100644 --- a/drivers/dax/super.c +++ b/drivers/dax/super.c @@ -86,12 +86,14 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize) { struct dax_device *dax_dev; bool dax_enabled = false; + pgoff_t pgoff, pgoff_end; struct request_queue *q; - pgoff_t pgoff; - int err, id; - pfn_t pfn; - long len; char buf[BDEVNAME_SIZE]; + void *kaddr, *end_kaddr; + pfn_t pfn, end_pfn; + sector_t last_page; + long len, len2; + int err, id; if (blocksize != PAGE_SIZE) { pr_debug("%s: error: unsupported blocksize for dax\n", @@ -113,6 +115,15 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize) return false; } + last_page = ALIGN_DOWN(part_nr_sects_read(bdev->bd_part) + - PAGE_SIZE / 512, PAGE_SIZE / 512); + err = bdev_dax_pgoff(bdev, last_page, PAGE_SIZE, &pgoff_end); + if (err) { + pr_debug("%s: error: unaligned partition for dax\n", + bdevname(bdev, buf)); + return false; + } + dax_dev = dax_get_by_host(bdev->bd_disk->disk_name); if (!dax_dev) { pr_debug("%s: error: device does not support dax\n", @@ -121,14 +132,15 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize) } id = dax_read_lock(); - len = dax_direct_access(dax_dev, pgoff, 1, NULL, &pfn); + len = dax_direct_access(dax_dev, pgoff, 1, &kaddr, &pfn); + len2 = dax_direct_access(dax_dev, pgoff_end, 1, &end_kaddr, &end_pfn); dax_read_unlock(id); put_dax(dax_dev); - if (len < 1) { + if (len < 1 || len2 < 1) { pr_debug("%s: error: dax access failed (%ld)\n", - bdevname(bdev, buf), len); + bdevname(bdev, buf), len < 1 ? len : len2); return false; } @@ -143,13 +155,20 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize) */ WARN_ON(IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API)); dax_enabled = true; - } else if (pfn_t_devmap(pfn)) { - struct dev_pagemap *pgmap; + } else if (pfn_t_devmap(pfn) && pfn_t_devmap(end_pfn)) { + struct dev_pagemap *pgmap, *end_pgmap; pgmap = get_dev_pagemap(pfn_t_to_pfn(pfn), NULL); - if (pgmap && pgmap->type == MEMORY_DEVICE_FS_DAX) + end_pgmap = get_dev_pagemap(pfn_t_to_pfn(end_pfn), NULL); + if (pgmap && pgmap == end_pgmap && pgmap->type == MEMORY_DEVICE_FS_DAX + && pfn_t_to_page(pfn)->pgmap == pgmap + && pfn_t_to_page(end_pfn)->pgmap == pgmap + && pfn_t_to_pfn(pfn) == PHYS_PFN(__pa(kaddr)) + && pfn_t_to_pfn(end_pfn) == PHYS_PFN(__pa(end_kaddr))) dax_enabled = true; put_dev_pagemap(pgmap); + put_dev_pagemap(end_pgmap); + } if (!dax_enabled) {