Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3490024imu; Sun, 11 Nov 2018 16:16:21 -0800 (PST) X-Google-Smtp-Source: AJdET5eHxAqS8dxbWdhrknZELqMEaecijLp3VNuuyhOgGNTUFUn09mYhiv4B+TRyTPf4vaawd+4x X-Received: by 2002:a17:902:50ec:: with SMTP id c41-v6mr17459827plj.176.1541981781395; Sun, 11 Nov 2018 16:16:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981781; cv=none; d=google.com; s=arc-20160816; b=NuSMm/EThmw72YOasbGpnxufzuz24ihJNnQdl8iRHl9sF24K6QWpCCIaxWmp1yo50Z 9ahk0bH89e4YUGPJpc5vdJZHzDIFZ+Tf3aT/uA64tcx8LmaRhu0qATy5wnrr5+8yL1ix 5Ppi3qGePM248PEgXAfdyv5pcsOk5cKWeRfAyRgjJlOOdfsC7XRCoO1j7XZiU9h/D+D6 5ygWCMXx4sX6vANqudhcOBR5slBlFirMGXhMCZ6cfs5deAptZzi6F/hqwbuJXkDwAvG3 7JMWR4zP7XT0BYX5wHbMztGPWsV95aeLbngTynMeUExUPCfpBRocArhgWfJLnzdUHKS8 2RnA== 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=2zIuAfMxVzeOnslwHyS2Zp05+nlN+C5vu3L3/lFoR9Y=; b=tvBS3EM8TSeP5HajGUWoRws4HQqKAJ49oa5bd5O3cuoZAHATjEwoK4y4ba26FuT/G1 /T+IC8Tm+U6Flcnibxbfx/K4JJFGracouRu4eEuvwfp8cwo1qO1oQQeZyF0ALvD0XpVs iiZXh4b7ykFPmeMqbJ6El04ELGFKITi8fDaA7KxcxZ3qtpe0iT1Xpgpt4/7ajTRnJEGR Es6opNS0wEW0au+ArvWjnWXuxiKEv18AOHAY3btdSFpsANN0xrU0MG40MZSwSe/A9Qw1 3ITXf9BIxNQjVGN0eHAE6g+hRanz6V5dhsk+zWkBicu7vnVBj27nvVpNUZEh5jccYDGq bPIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KamkoBw2; 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 m2-v6si17823840pfb.66.2018.11.11.16.16.06; Sun, 11 Nov 2018 16:16:21 -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=@kernel.org header.s=default header.b=KamkoBw2; 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 S1730382AbeKLIRL (ORCPT + 99 others); Mon, 12 Nov 2018 03:17:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:59152 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730203AbeKLIRI (ORCPT ); Mon, 12 Nov 2018 03:17:08 -0500 Received: from localhost (unknown [206.108.79.134]) (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 B2629223CB; Sun, 11 Nov 2018 22:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975232; bh=0bm05sZ3E4IGUJ6UWO2cY+cvtxxufx6NU4CMx9Kii6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KamkoBw2Dk1ZChq+W2w0lliwLTel4zJxHVpMwo6qZNL6FBqZQ+S4ZOIRX9uFByi1y cOCeZv9UST0tEOaqcC6bKShLApEo30V0LlqxBR1Zy6GIe7nw6qEzYuq+FYFqGOJ1el FgAcCVYDW38PiXjkfS8ibEN5IAWqffCm8Geac4LI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 060/361] lightnvm: pblk: fix race on sysfs line state Date: Sun, 11 Nov 2018 14:16:47 -0800 Message-Id: <20181111221628.365024118@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Javier González [ Upstream commit 44cdbdc657b23f75736eca3e88b781f009104363 ] pblk exposes a sysfs interface that represents its internal state. Part of this state is the map bitmap for the current open line, which should be protected by the line lock to avoid a race when freeing the line metadata. Currently, it is not. This patch makes sure that the line state is consistent and NULL bitmap pointers are not dereferenced. Signed-off-by: Javier González Signed-off-by: Matias Bjørling Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/lightnvm/pblk-core.c | 5 +++-- drivers/lightnvm/pblk-sysfs.c | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) --- a/drivers/lightnvm/pblk-core.c +++ b/drivers/lightnvm/pblk-core.c @@ -1539,13 +1539,14 @@ struct pblk_line *pblk_line_replace_data struct pblk_line *cur, *new = NULL; unsigned int left_seblks; - cur = l_mg->data_line; new = l_mg->data_next; if (!new) goto out; - l_mg->data_line = new; spin_lock(&l_mg->free_lock); + cur = l_mg->data_line; + l_mg->data_line = new; + pblk_line_setup_metadata(new, l_mg, &pblk->lm); spin_unlock(&l_mg->free_lock); --- a/drivers/lightnvm/pblk-sysfs.c +++ b/drivers/lightnvm/pblk-sysfs.c @@ -262,8 +262,14 @@ static ssize_t pblk_sysfs_lines(struct p sec_in_line = l_mg->data_line->sec_in_line; meta_weight = bitmap_weight(&l_mg->meta_bitmap, PBLK_DATA_LINES); - map_weight = bitmap_weight(l_mg->data_line->map_bitmap, + + spin_lock(&l_mg->data_line->lock); + if (l_mg->data_line->map_bitmap) + map_weight = bitmap_weight(l_mg->data_line->map_bitmap, lm->sec_per_line); + else + map_weight = 0; + spin_unlock(&l_mg->data_line->lock); } spin_unlock(&l_mg->free_lock);