Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp617290img; Fri, 22 Mar 2019 05:14:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8/pfYEuOQd4pubQAWvGIN8iZUZgGAHYxioDIquwuNs1Dtpz1WfHN8eOlintJ0ZXebzFXw X-Received: by 2002:a62:b61a:: with SMTP id j26mr8729924pff.151.1553256893821; Fri, 22 Mar 2019 05:14:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553256893; cv=none; d=google.com; s=arc-20160816; b=LSkIY+dznn1yZRWrsh57Hs1b/d2KaGAJP8/821l5k3t70+fr8s1QBOEU3E9VyLdDF3 R/jH0OotqCL7/repW8V84Mb0PWq5JgzKhSg7OFUVpijKPPC7ygPgSEbi0o5JTYSPz1Ae DyLu8Rvs9pN9MZIaxUIOU1GvfCmezQItwwXKUHLy9GbJp+RTTDTrxasARz2qm6nwj6oZ HL7lhIZsGEXI3UGYsyfemyzMTq84cGsmASDu9iSe6JN4Co6axiee8L9MXoGDyQ1BhIYu NCpCWxdJSnpxeq51EgQRJiouHt+63C44pfW3wj/aVwRsJr100sbxZTXuSYFCAJZ8DnV0 ckOw== 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:subject:cc:to :from:dkim-signature; bh=P36bBky6EJB4CRK9rL4F1/EO7yn6vILBZlfeqNgXu8o=; b=eQenah6wCmfWfT6uP++qM7srrz+i01g0eJdR/KskSLYjxnwBJOPMiZZXB9LHgHkMj+ 6b8MFnt9/JZnPIO/oaSWXlXCDRY4rBlabNWq/YDkQ2NNHS0yoi6WPFTVtr0w39AKGI58 wxkw2RpozcKgJDUmADotNlf9hsUoHdM7L2T0YzK3YkZyYr0vSJ1mcWAPBiHL90tOfRGI s3HDW0NMqnPTtS+h5+2GWc4I5J5c4g9A7jjLoe5YjQs2b51e/GfjaiEy4SxhcU05wWDl 9yRbrElpuemy011TDHBDEEkpHQ/n+S7kZ5cVTx6+VcN5SbjjpldXs8bPpjvjF3axk/e8 NOqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uKmk9K2+; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g98si7176194plb.11.2019.03.22.05.14.38; Fri, 22 Mar 2019 05:14:53 -0700 (PDT) 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=@kernel.org header.s=default header.b=uKmk9K2+; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389380AbfCVMMs (ORCPT + 99 others); Fri, 22 Mar 2019 08:12:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:50968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389651AbfCVMMq (ORCPT ); Fri, 22 Mar 2019 08:12:46 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4248E2082C; Fri, 22 Mar 2019 12:12:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553256765; bh=QIb2Dl+Qv6AD2dnHXdkHLS/YQ455Te1K/YTHSYyJ++g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uKmk9K2+Cb5OH/TVPPWqNOJ17hIsulaZKDJeR7wPAjd0NcgBB0o7+VEEHy3aa9XiU APeAUOkCMj2IFs6g0lPAnKvG6CzvKsUpQkXiFswafXPYPgTAd5VcB+wR1MkdOSnODF uiocusdtI1FXi58UDUtf3wMmo3PpTJcHuXBaLzgA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kelly Couch , Dan Williams Subject: [PATCH 5.0 031/238] libnvdimm/label: Clear updating flag after label-set update Date: Fri, 22 Mar 2019 12:14:10 +0100 Message-Id: <20190322111300.107932286@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams commit 966d23a006ca7b44ac8cf4d0c96b19785e0c3da0 upstream. The UEFI 2.7 specification sets expectations that the 'updating' flag is eventually cleared. To date, the libnvdimm core has never adhered to that protocol. The policy of the core matches the policy of other multi-device info-block formats like MD-Software-RAID that expect administrator intervention on inconsistent info-blocks, not automatic invalidation. However, some pre-boot environments may unfortunately attempt to "clean up" the labels and invalidate a set when it fails to find at least one "non-updating" label in the set. Clear the updating flag after set updates to minimize the window of vulnerability to aggressive pre-boot environments. Ideally implementations would not write to the label area outside of creating namespaces. Note that this only minimizes the window, it does not close it as the system can still crash while clearing the flag and the set can be subsequently deleted / invalidated by the pre-boot environment. Fixes: f524bf271a5c ("libnvdimm: write pmem label set") Cc: Cc: Kelly Couch Signed-off-by: Dan Williams Signed-off-by: Greg Kroah-Hartman --- drivers/nvdimm/label.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -755,7 +755,7 @@ static const guid_t *to_abstraction_guid static int __pmem_label_update(struct nd_region *nd_region, struct nd_mapping *nd_mapping, struct nd_namespace_pmem *nspm, - int pos) + int pos, unsigned long flags) { struct nd_namespace_common *ndns = &nspm->nsio.common; struct nd_interleave_set *nd_set = nd_region->nd_set; @@ -796,7 +796,7 @@ static int __pmem_label_update(struct nd memcpy(nd_label->uuid, nspm->uuid, NSLABEL_UUID_LEN); if (nspm->alt_name) memcpy(nd_label->name, nspm->alt_name, NSLABEL_NAME_LEN); - nd_label->flags = __cpu_to_le32(NSLABEL_FLAG_UPDATING); + nd_label->flags = __cpu_to_le32(flags); nd_label->nlabel = __cpu_to_le16(nd_region->ndr_mappings); nd_label->position = __cpu_to_le16(pos); nd_label->isetcookie = __cpu_to_le64(cookie); @@ -1249,13 +1249,13 @@ static int del_labels(struct nd_mapping int nd_pmem_namespace_label_update(struct nd_region *nd_region, struct nd_namespace_pmem *nspm, resource_size_t size) { - int i; + int i, rc; for (i = 0; i < nd_region->ndr_mappings; i++) { struct nd_mapping *nd_mapping = &nd_region->mapping[i]; struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); struct resource *res; - int rc, count = 0; + int count = 0; if (size == 0) { rc = del_labels(nd_mapping, nspm->uuid); @@ -1273,7 +1273,20 @@ int nd_pmem_namespace_label_update(struc if (rc < 0) return rc; - rc = __pmem_label_update(nd_region, nd_mapping, nspm, i); + rc = __pmem_label_update(nd_region, nd_mapping, nspm, i, + NSLABEL_FLAG_UPDATING); + if (rc) + return rc; + } + + if (size == 0) + return 0; + + /* Clear the UPDATING flag per UEFI 2.7 expectations */ + for (i = 0; i < nd_region->ndr_mappings; i++) { + struct nd_mapping *nd_mapping = &nd_region->mapping[i]; + + rc = __pmem_label_update(nd_region, nd_mapping, nspm, i, 0); if (rc) return rc; }