Received: by 10.213.65.68 with SMTP id h4csp514002imn; Fri, 16 Mar 2018 10:03:52 -0700 (PDT) X-Google-Smtp-Source: AG47ELtNkqvSLnyAxr7LroY9Rlo8fotIVmBj8dFS5jsXn5BXgpDYiVFyzjDwkkIk4zvXXFSNNGnA X-Received: by 10.101.66.193 with SMTP id l1mr1997001pgp.57.1521219832828; Fri, 16 Mar 2018 10:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521219832; cv=none; d=google.com; s=arc-20160816; b=ZNrUasmOkurB6+4r29mt3mWU/BXt31gen1PoY2IOC8iSerx7K4JY8iVuTAaTLmzFKn A/QvQvmei78YeQJ+P3v9X9/PKaGUDS5P/ngDhCt7xOeJ91qO7OWcvwHvE6O1OYkw376w FVTzSw6HjnG+BGhgJNTkhHvSmpbpsI6Oz5rVQLeySjeP6BmLn79pyNPerZzqFGH/LcpZ Yy9wu1BXvzYa2meWdiN63wldad4loA/5qeLXhgdMtFttXoi84/Pqz8uDtiAx6d638eaU itQq1n4LObiQTAdLpUiWWAESN6CDoWqwrMSMBgZOT/3sE5JIjMwVvbxq0IxUiV5wQ4WY FH+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=rwCx8kmwCbVmKkL/BS45rv3v4rKX0KvmZljrsixpB0c=; b=B1xQHhqCgtBIvOnUkMj+pybQZY2iMW8ellUcipMOBRp7bMU4E15lwpLXZy8KU7/H+x lcnoBp9J5sseYbgE+58uulHrnMFsy+iqAf4nIBUgQZbMZYLtQFEkXv0CpUNvfmyq0xnp NhzYPOSF1OTqFhmSr99vNjdT/YhMn3+5lUSTKZXQsCMuoUV7NZx8n3OK07mKBKo/WFpb XgQCOTErTxhwBd5/A1tSPWKcGEC+7pKQQ6Fx9SgeeXT8hBlIF6Z5p8/MDIlnCqfufwMC gBwMxXtKqUonQFcnG+AG97LgLQwtezgD/isSE8esNypTBsIy32+m60tfVkEvtTDrcFDk k7jQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k71si5109469pga.68.2018.03.16.10.03.37; Fri, 16 Mar 2018 10:03:52 -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; 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 S933237AbeCPRBi (ORCPT + 99 others); Fri, 16 Mar 2018 13:01:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38084 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933587AbeCPPch (ORCPT ); Fri, 16 Mar 2018 11:32:37 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B55D611F0; Fri, 16 Mar 2018 15:32:36 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Clay McClure , Richard Weinberger Subject: [PATCH 4.9 65/86] ubi: Fix race condition between ubi volume creation and udev Date: Fri, 16 Mar 2018 16:23:28 +0100 Message-Id: <20180316152321.777135868@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152317.167709497@linuxfoundation.org> References: <20180316152317.167709497@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Clay McClure commit a51a0c8d213594bc094cb8e54aad0cb6d7f7b9a6 upstream. Similar to commit 714fb87e8bc0 ("ubi: Fix race condition between ubi device creation and udev"), we should make the volume active before registering it. Signed-off-by: Clay McClure Cc: Signed-off-by: Richard Weinberger Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/ubi/vmt.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c @@ -265,6 +265,12 @@ int ubi_create_volume(struct ubi_device vol->last_eb_bytes = vol->usable_leb_size; } + /* Make volume "available" before it becomes accessible via sysfs */ + spin_lock(&ubi->volumes_lock); + ubi->volumes[vol_id] = vol; + ubi->vol_count += 1; + spin_unlock(&ubi->volumes_lock); + /* Register character device for the volume */ cdev_init(&vol->cdev, &ubi_vol_cdev_operations); vol->cdev.owner = THIS_MODULE; @@ -304,11 +310,6 @@ int ubi_create_volume(struct ubi_device if (err) goto out_sysfs; - spin_lock(&ubi->volumes_lock); - ubi->volumes[vol_id] = vol; - ubi->vol_count += 1; - spin_unlock(&ubi->volumes_lock); - ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); self_check_volumes(ubi); return err; @@ -328,6 +329,10 @@ out_sysfs: out_cdev: cdev_del(&vol->cdev); out_mapping: + spin_lock(&ubi->volumes_lock); + ubi->volumes[vol_id] = NULL; + ubi->vol_count -= 1; + spin_unlock(&ubi->volumes_lock); if (do_free) ubi_eba_destroy_table(eba_tbl); out_acc: