Received: by 10.223.185.116 with SMTP id b49csp2302659wrg; Thu, 15 Feb 2018 09:30:41 -0800 (PST) X-Google-Smtp-Source: AH8x224oUprPYLiYDtATf/LEESLGWcdVgb6K+pll6tQ9SfBRxn5FqbSaMXaGvelBcLxcYbzgarWj X-Received: by 10.99.158.17 with SMTP id s17mr2846972pgd.64.1518715841145; Thu, 15 Feb 2018 09:30:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518715841; cv=none; d=google.com; s=arc-20160816; b=Xo3+vvxIr/e38cP0fPOnXew6HK7hprXpC8yTUnsiafi4MUvARiRP/KZ45kYGNNpMpb HNxiznkUnDTl5U2B3J5Cn3zuJyKcO1UVEDy3Hqd38I/9EgaeVJu3qsWurmdEfygO22i7 sx8ld4u2WlqbNXqYhcEbmiJHircN1ajortHTw7i+cGyGYsmYfHHKqXXJ/ok32GajF8Z5 9lcF8DDRwlwnfqzW4AGBgTM1JsyS52r1FAYf3VwGXWsclO7ADNfFvOo5slCcYpTjxpln 3OO9Aq5xaB6jOzEbWDuZqpE1yOs7k0mlR92tReRAf0cnPs7RxikD3eFsYTrygImKZLGV cHvQ== 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=d5JwATqItvZ90NwbCdTJ8i8LbuxbbrBwDNSzjUS+h9Y=; b=ITfKZJWz/ShiT4w+/UPSnk6KRwm1wENUhTdYTuzZ2daRr0BCwgnm4MtiV8nZReix8c cuPH8NEAm4/kqYSi2a9FjM8JxZ9kLQ8eavEPVE8FLAIoERUOjkzcJrRIQDUoUHU9oOKw dWteC8cYfFN70zS973HBbs7siv54qXA1EY8TqVImMUZFbpdsvU1UXsLUOunH9t5bLAxY hshzG62kYgy5NBdHHYPWhrhAWgCLAqvGRP1kpwMqu56KZEgm22QGEBXWWmn5EdBfFKAQ 9zwRF2eJ5Yb5OMQafFzJ1D+AaMWiCf0WuAwEeOPSJImVBUlH3EAAS+0t0i8h71EEXSsQ 6Ukw== 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 q10si1274239pgd.335.2018.02.15.09.30.25; Thu, 15 Feb 2018 09:30:41 -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 S1165005AbeBOPd6 (ORCPT + 99 others); Thu, 15 Feb 2018 10:33:58 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:56964 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164993AbeBOPd4 (ORCPT ); Thu, 15 Feb 2018 10:33:56 -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 5D79110D2; Thu, 15 Feb 2018 15:33:55 +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.14 099/195] ubi: Fix race condition between ubi volume creation and udev Date: Thu, 15 Feb 2018 16:16:30 +0100 Message-Id: <20180215151710.642247933@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151705.738773577@linuxfoundation.org> References: <20180215151705.738773577@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.14-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);