Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2129168pxb; Mon, 12 Apr 2021 15:25:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFPOB4O/1wzuXDnV/PW0leJGBvFKhC5yhrIm1vaAgY/d7dxNX+qfW//wkpq8jLuJhwd7HH X-Received: by 2002:a17:90a:9509:: with SMTP id t9mr1492170pjo.3.1618266347685; Mon, 12 Apr 2021 15:25:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618266347; cv=none; d=google.com; s=arc-20160816; b=ub60G4KZ4uW0LQ3ma9RwxHSFAcKeoJA5scQHoEKeCB1RVdnou3EvaIs0gQwlrQfAQD 8eM8C6U7jTSFNjsIMHfueKjAa3azll3oInxtZf2xjvxfqd5GAeo0brXcrl1+f7b1Nzjy MPnPxRxrK3fMHcwSVdaTqkSm5QeSOQ/mCX8hQOiYj+Q8pQgCzhM7X/1ctcJjrjZKIrCw 98e2QLOpGs7qJ+l7OrAeBmLpE3s1fyJvmbEISa+7YfHR/uDA4PDI0eF27hYPWnP0zscT VCt89PDLQkHxAi8AT1fIzL9sowzcQjnLuVy4VBkIGBm6Ol7S+fdcI1yi7gQNs6tCb+oa /97g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/w3YQcsLt0tTt21HyQFW1RBi/VyFmgIjiKKeFgTmBsM=; b=b+si/1vGuz6rLH6fxuGwbILt+84GJvSNyQGlWPxi013u3oTKO48iqVR8+A3PEHfe/B OOiY4JnilzV7quIKID3h5Kf2oIvfCVL34x3AFjQFNwdvEMzVAD3WKX7O8vMH4P69x1BM /CjwdxbGpbVS+mf/NxF12y7btjFlA9FmGIzKoqNk+xC6VEd/yLK0XohfjqVm2odZPXVZ lhV1cASzmTCzAS0jkLzC3R5n96p3rvvKH0xysyvGZdkPCAC2VXTh5Nfldmtf7n96V3II IaPs208UG9NsJYLFjJVF63jlkk3TUNoAQ91gn9I58XCG3uw8imYmvHSrDhDVPR/x2v41 GseQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="MKmmI/RM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m136si15497688pga.183.2021.04.12.15.25.34; Mon, 12 Apr 2021 15:25:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="MKmmI/RM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242568AbhDLJ26 (ORCPT + 99 others); Mon, 12 Apr 2021 05:28:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:54564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240228AbhDLJFO (ORCPT ); Mon, 12 Apr 2021 05:05:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C8D566135A; Mon, 12 Apr 2021 09:02:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618218138; bh=frdF8M4X2fy+10Gp7tFNWmoY2xvOCK0S4zLMJ7tAeI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MKmmI/RM2KliyGaw6rr4xcbCl0ubwdAXfc6H+i6WbVyS1QySZoOAfzxL/FomrGhPa 7/nETUcp8m03xSfYOkj4p6I2+NGyLP8HjBnCwRq6aryqE497tukvbbNAuzOUDUgdwn Oj4ipftbJ5tkxby+KP+af4U2X14h5TI+9ZGqf4QY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Saravana Kannan Subject: [PATCH 5.11 084/210] driver core: Fix locking bug in deferred_probe_timeout_work_func() Date: Mon, 12 Apr 2021 10:39:49 +0200 Message-Id: <20210412084018.811742487@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412084016.009884719@linuxfoundation.org> References: <20210412084016.009884719@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Saravana Kannan commit eed6e41813deb9ee622cd9242341f21430d7789f upstream. list_for_each_entry_safe() is only useful if we are deleting nodes in a linked list within the loop. It doesn't protect against other threads adding/deleting nodes to the list in parallel. We need to grab deferred_probe_mutex when traversing the deferred_probe_pending_list. Cc: stable@vger.kernel.org Fixes: 25b4e70dcce9 ("driver core: allow stopping deferred probe after init") Signed-off-by: Saravana Kannan Link: https://lore.kernel.org/r/20210402040342.2944858-2-saravanak@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/dd.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -292,14 +292,16 @@ int driver_deferred_probe_check_state(st static void deferred_probe_timeout_work_func(struct work_struct *work) { - struct device_private *private, *p; + struct device_private *p; driver_deferred_probe_timeout = 0; driver_deferred_probe_trigger(); flush_work(&deferred_probe_work); - list_for_each_entry_safe(private, p, &deferred_probe_pending_list, deferred_probe) - dev_info(private->device, "deferred probe pending\n"); + mutex_lock(&deferred_probe_mutex); + list_for_each_entry(p, &deferred_probe_pending_list, deferred_probe) + dev_info(p->device, "deferred probe pending\n"); + mutex_unlock(&deferred_probe_mutex); wake_up_all(&probe_timeout_waitqueue); } static DECLARE_DELAYED_WORK(deferred_probe_timeout_work, deferred_probe_timeout_work_func);