Received: by 10.223.185.116 with SMTP id b49csp155746wrg; Thu, 15 Feb 2018 18:47:49 -0800 (PST) X-Google-Smtp-Source: AH8x226QqZbfJVda25ofUqd2aAdHdsp4D/stDtnG6KwQdlRU268EaXuHqIPlVCR3mlz8KP0ufoOC X-Received: by 2002:a17:902:b081:: with SMTP id p1-v6mr4374036plr.314.1518749269572; Thu, 15 Feb 2018 18:47:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518749269; cv=none; d=google.com; s=arc-20160816; b=m1gfzR9YkFP3RsrjiFtcCByFLx6e5CXzq3Qv/d+vvLxTVrnKARouryNBer2D0cgpJ6 j7VBAdUJ3HvE4GtJRiVsnrbnZNMp2X9kceO11L2cr2+m+KKR+lOicTav3+pqV8tUzOQ0 1RAcfLSwoD2MVWhE8XSOghei5xVK3bOds+m42vIm1avp4NotCHNjWSesoJZSMnXVcA1y NmbbqDZLW0aHFEFIsJdzbBGuDEXEiYwsakPHQGRgSI0kfjlpCtV3YfpOGd2xfv/8HWWt /r7FEdOqZjiaPqRU0UuvzbdAxVQ+hzOiKVk1M68WgFIzDESXsLkFDEOPq9TFH2UPmCr7 tnMA== 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=C5LdO8t+Pw5kG2LJl2MT4MT0cKC06h0/kgpjBSvAveY=; b=00IHSUSdeoV/tVz7w72R88g6/lqlFSeDo1uRTuWdw1JaFCN56GaLMCUaXcrlGgNfUX DR8DW7dJpVR/abGmx+j8Zq8HtEQqcUcCErZLNwZz/DR30W1qnb/ThnEVFGmwklnN0h+q JsTzfi16IAgOHUMpAaRKa0ZC0IySDDdk0NknkVDkEbVQWp4Bzfoab/84uZ9zEkAZXO3k ZdR83Rv/ImigqFSsJ0ew2/uzs9cuP3JWQAwPsNNhYJGs84Pw2OvQGxARYoKlV9LLsViv srI/NT1QmSXB4W8lfJKKqPwn/VFhgOMtSptwtD+RwCufLRZ8fLMGUfq5Aw2qP3rDTdwY Rjqg== 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 b7si3681728pgr.640.2018.02.15.18.47.34; Thu, 15 Feb 2018 18:47:49 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1165504AbeBOPof (ORCPT + 99 others); Thu, 15 Feb 2018 10:44:35 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34378 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1165417AbeBOPoa (ORCPT ); Thu, 15 Feb 2018 10:44:30 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 14787117F; Thu, 15 Feb 2018 15:44:29 +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.15 092/202] ubi: Fix race condition between ubi volume creation and udev Date: Thu, 15 Feb 2018 16:16:32 +0100 Message-Id: <20180215151718.219945743@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@linuxfoundation.org> User-Agent: quilt/0.65 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.15-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 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 @@ -270,6 +270,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; @@ -298,11 +304,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; @@ -315,6 +316,10 @@ out_sysfs: */ cdev_device_del(&vol->cdev, &vol->dev); out_mapping: + spin_lock(&ubi->volumes_lock); + ubi->volumes[vol_id] = NULL; + ubi->vol_count -= 1; + spin_unlock(&ubi->volumes_lock); ubi_eba_destroy_table(eba_tbl); out_acc: spin_lock(&ubi->volumes_lock);