Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp546637pxj; Thu, 17 Jun 2021 08:26:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/ePXfBmqvPxo2vxV6CjIjP32C1OGXP3ugz+Kcs5soLrQiJBGiKE/c40WCl1CKSWGg9Sxi X-Received: by 2002:a5d:9acd:: with SMTP id x13mr4363866ion.134.1623943565331; Thu, 17 Jun 2021 08:26:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623943565; cv=none; d=google.com; s=arc-20160816; b=k5CVH5PBACm4OlMV94oHuHsRo08xsu/+bJ9Alc7mfNQBijH0fcv+uw4Y9ThKv5dMDd dzwvG8BCXYgwp48pzCWmrJ8GHi6/JLPkZcu9ydIBQtGFeg8ekNOY6rcg872TYc2uhox2 QkLDfJk3CsBzwIMidGQ3hgJw6Aj1QEIPlJ7WTqxgo7ILRJjvL73N9CjxuQ/zBfJm0clH iCiOaizEl7ES7lx3RZ+J2n/YhsaRSF7KLmsQiiggewSNVYpmISmVVnBhiAOcBipOwpNr U9fAvN3qKUQeOWsgMxmXc4hXb6YBOKHa/n97yV4qhTcHOIbt4ah5cly8wvDgmzJkeccz OKbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=BGbeP7ZnDkY2DJidMpRViqieliUtB17GFMkW1zVFjRU=; b=ugHk8XQbku7Q5kIz08giiaLiDKQfOVuLYqeVcU3bTl/L5w9B7YWXPqiJwj+/0JT27O 9BWQBytzsuYNMuuDqG9l78P5sgcdT8HrcPJS8A3mg+oG+knGyR0uReCBJaRsEWclmodw eWgz7J+hKhJTpTP5DMDWMpVsEoCiRyGryqHBu0yqNm8i2aRbAMLmxAZxr3pm9eTtTcQv OVhCfLoXUfytheL8UwrCwtanHGnxfGwhlm7uTwn106K8tTz5nJZbY8KmlL779DT+iPUM ZiNQD92j/l9YLT23cv/g2d9dPXqIzUMBeeRTPTPWjDWyvyPynDX9c88nY/fQ83QuTXzf OoMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Oa3ubTr0; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c15si5492254iln.17.2021.06.17.08.25.52; Thu, 17 Jun 2021 08:26:05 -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=@gmail.com header.s=20161025 header.b=Oa3ubTr0; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233256AbhFQPZw (ORCPT + 99 others); Thu, 17 Jun 2021 11:25:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233130AbhFQPZu (ORCPT ); Thu, 17 Jun 2021 11:25:50 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C7E6C061574; Thu, 17 Jun 2021 08:23:42 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id y15so5283035pfl.4; Thu, 17 Jun 2021 08:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=BGbeP7ZnDkY2DJidMpRViqieliUtB17GFMkW1zVFjRU=; b=Oa3ubTr0Q6/AN8zuP9Ab/2Kl+m1AAVUY/MDQf2YhYJMxoR2QNRnHh/uPRS4KEd8FwY 7lYpYXWtliofo4M15KX6kB/FCkMTAvkAF5RyYzkFKpXKvFcmdbiszr2IFGVTZVh653X0 JlXGmk/4/4qPnXOO/m3zhD3PlhS2nlPXPnbBDrYB95ZdveGJ8MePV/9NK38Q1rNXPizi QKad2ZO6qF2xPjJ6PWs5ki8uHBBzjnc1piJNAtBZfryD4TVocKpZsNdt08Prz2cW6xPh dwpLwl/ECtvKrpW71zqf6I/ocCQRj1JzvqPxhMJBmEKXb5ymNHU6ksoRABqmBJzbHy7l YMpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=BGbeP7ZnDkY2DJidMpRViqieliUtB17GFMkW1zVFjRU=; b=PIWp0ZoCiSnAjkgrrXWJZ43NxUBoRi9I5seWERZ2liYi6+BefaXzV91K2vGVF/PJ4d gyAsgrrCv38bbwNO1cVkegwXFPwXfTmhO/zHF6OaFcrZRh67M3EGwhkwT+RZpOAWK8Nf 8ziG223Kk4pOSiukybsE4TX2djJjKEb1HcUE7/yDGaJiTc5CHGCUK9QrVmbMIARFpf+I ounQutBb2Jgljh/0ao13CuaLvifUJCW2L5E2bBjzoLrGScGngC7EKlQnu1ke+WxctvrW /EFctzbQe6MNrytUU6YfVeaWA17dK2ezF3AKD+KwgeCq0VcWUySgeAzzYqGE0IAZU1GQ /aJg== X-Gm-Message-State: AOAM530fF75sPLe7mTLAYADIrWdDEVZRH0h+lxeOUTXVC52fA4pLsxoK 1RfDVsGnHG3t0yTWvzh8EWA= X-Received: by 2002:aa7:905a:0:b029:2f6:d759:6c2d with SMTP id n26-20020aa7905a0000b02902f6d7596c2dmr249155pfo.33.1623943421659; Thu, 17 Jun 2021 08:23:41 -0700 (PDT) Received: from [192.168.1.237] ([118.200.190.93]) by smtp.gmail.com with ESMTPSA id v6sm6434212pgk.33.2021.06.17.08.23.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Jun 2021 08:23:41 -0700 (PDT) Subject: Re: [PATCH] block: break circular locks in blk_request_module To: Christoph Hellwig Cc: axboe@kernel.dk, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, syzbot+6a8a0d93c91e8fbf2e80@syzkaller.appspotmail.com, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, linux-mtd@lists.infradead.org References: <20210617092016.522985-1-desmondcheongzx@gmail.com> From: Desmond Cheong Zhi Xi Message-ID: Date: Thu, 17 Jun 2021 23:23:36 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/6/21 7:51 pm, Christoph Hellwig wrote: > On Thu, Jun 17, 2021 at 05:20:16PM +0800, Desmond Cheong Zhi Xi wrote: >> mutex_lock(&major_names_lock); >> for (n = &major_names[major_to_index(major)]; *n; n = &(*n)->next) { >> if ((*n)->major == major && (*n)->probe) { >> - (*n)->probe(devt); >> + probe = (*n)->probe; >> mutex_unlock(&major_names_lock); >> + probe(devt); > > And now you can all probe after it has been freed and/or the module has > been unloaded. The obviously correct fix is to only hold mtd_table_mutex > for the actually required critical section: > Thank you for the correction, Christoph. I hadn't thought of the scenario where the module is unloaded. I'll be more conscientious in the future. > diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c > index fb8e12d590a1..065d94f9b1fb 100644 > --- a/drivers/mtd/mtd_blkdevs.c > +++ b/drivers/mtd/mtd_blkdevs.c > @@ -529,13 +529,11 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr) > register_mtd_user(&blktrans_notifier); > > > - mutex_lock(&mtd_table_mutex); > > ret = register_blkdev(tr->major, tr->name); > if (ret < 0) { > printk(KERN_WARNING "Unable to register %s block device on major %d: %d\n", > tr->name, tr->major, ret); > - mutex_unlock(&mtd_table_mutex); > return ret; > } > > @@ -545,12 +543,12 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr) > tr->blkshift = ffs(tr->blksize) - 1; > > INIT_LIST_HEAD(&tr->devs); > - list_add(&tr->list, &blktrans_majors); > > + mutex_lock(&mtd_table_mutex); > + list_add(&tr->list, &blktrans_majors); > mtd_for_each_device(mtd) > if (mtd->type != MTD_ABSENT) > tr->add_mtd(tr, mtd); > - > mutex_unlock(&mtd_table_mutex); > return 0; > } > This fix passes the Syzkaller repro test on my local machine and on Syzbot. I can prepare a v2 patch for this. May I include you with the Co-developed-by: and Signed-off-by: tags? If another tag would be more appropriate, or if you want to submit the patch yourself, please let me know. Best wishes, Desmond