Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp503334imw; Fri, 8 Jul 2022 06:50:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u6ZNcIG6Azfu2yvGWAINYPk54LqTbXMn2Oah+Q3ACnsTH4fIBqpUbiLt3HyUo4EXsskcwA X-Received: by 2002:a17:907:1c83:b0:726:2d64:6c5e with SMTP id nb3-20020a1709071c8300b007262d646c5emr3609543ejc.610.1657288206887; Fri, 08 Jul 2022 06:50:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657288206; cv=none; d=google.com; s=arc-20160816; b=cgIEtAs/jZVcDaPb8WhnWa+3CXBZprnjf8fQsTLd0/8hw7+0M0M5q/nG6Zycy06RjC ibFS4FMP1lAK9/PgZcIxqSGyu+oM/zKGUX9tTdmNmfmRdlGvl09NMXr0FQO0M3hT6YEm RmDOWTioZVMuE4/yjLQO3XrKsn18jEW6jgieDICTxRWotidSgd/XjUnrP53mU/M3ipm8 HHyC/HJCaQjjUy/fRAODyC11QXctj1AFrT2b05LN9pBPxyBxHYcPz37EfQfqFOg3zuKF PgmxmiB4vzJB0I4/yoe1NvW+4enukpHD7adOAphuL5SGN6IlasYcPe1RimYKGRZhTeLe 0coA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pEqRaU5WGG+euLna5TmW6w9vr09RYXmkfuZ0eJ7IJ4M=; b=goTvA8eE8EgKrv9dgGxcltJ33NHpW8Qune8WW57aOSC5xzSbcoEDOka6BlzKDBum5Q wFwFRL+1kxTAz6PPqdammsmKymZ+PfIXz46JkGUWtVzMV+8Wb+tYSOEn7kXPM4FGRBSu CVeM8g44/8am1PzlvgvHq1MijnMmRUux3Y4VTby55gyPCIBJiDmekeXXCG1OziSSVxYb wdDtSA+2fFxvpSSzCoLN0l0cOrp6s+i7jD55ihe3oUwVgXKbARnC9PR9dtAfENjPgOa3 Eq1k9ZQwcuJZVrU2x7HlKy+x2Pf3cHJT4f7ZliG8jeJRuZ6IQPdmWuEwvM4OlEgA60ro 4gNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JVqCQDj+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a16-20020aa7d910000000b0043a16087127si6893600edr.180.2022.07.08.06.49.40; Fri, 08 Jul 2022 06:50:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JVqCQDj+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S238364AbiGHNiO (ORCPT + 99 others); Fri, 8 Jul 2022 09:38:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238180AbiGHNiN (ORCPT ); Fri, 8 Jul 2022 09:38:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73ABC2B263; Fri, 8 Jul 2022 06:38:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DD5B9627C7; Fri, 8 Jul 2022 13:38:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDDDBC341C0; Fri, 8 Jul 2022 13:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657287491; bh=wK8QI0KUUCmliRxXY/niLWlbOMMhz5LkuejgEQenrck=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JVqCQDj+8dtEox91DR71hKsaQLCPHqCNS01zsg2jz+W1Wop9LCEOtQ7NylzWY4QSS aZN2mWaSrTsj+BNqMmnmpJrtcCc0K9jmevFgFV1X8BcXDX+wL0fd+7/679Vo1CtbZE SE/2UC9C0ogyl2RWR4RAyjruluzzHKqjgHNAxDiQ= Date: Fri, 8 Jul 2022 15:37:33 +0200 From: Greg KH To: Tetsuo Handa Cc: Oliver Neukum , "Rafael J. Wysocki" , Wedson Almeida Filho , Len Brown , Pavel Machek , Arnd Bergmann , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Dmitry Vyukov , Arjan van de Ven Subject: Re: [PATCH] char: misc: make misc_open() and misc_register() killable Message-ID: References: <617f64e3-74c8-f98b-3430-bd476867e483@I-love.SAKURA.ne.jp> <5665ccb2-b92b-9e1f-8bb5-a950986450ec@I-love.SAKURA.ne.jp> <064bbe2a-c18e-203e-9e01-b32fe9baa390@I-love.SAKURA.ne.jp> <7ddb25ff-60e5-75be-8080-2a7465cca68c@I-love.SAKURA.ne.jp> <815866b5-842e-4829-5ed8-26a5f1e856a4@suse.com> <22c61a75-8140-c62d-ffe0-efd6e9fa38ee@I-love.SAKURA.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <22c61a75-8140-c62d-ffe0-efd6e9fa38ee@I-love.SAKURA.ne.jp> X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 07, 2022 at 02:06:38PM +0900, Tetsuo Handa wrote: > Let's summarize current location: > > (1) Greg wants me to fix snapshot_open() not to sleep for too long, instead of > making misc_open() killable. > > (2) I found snapshot_open() calls wait_for_device_probe() which might sleep > long enough to consider as hung up due to: > > (a) One of existing probe request got stuck due to unresponsive hardware. > > (b) New probe requests come in before existing probe requests complete. > > (3) Because of (2), it is difficult to guarantee snapshot_open() not to sleep for > too long. > > (4) Because of (3), calling file->f_op->open(inode, file) with misc_mtx held can > block mutex_lock(&misc_mtx) too long. This is the phenomenon syzbot is reporting. > > Initial mitigation was to replace mutex_lock(&misc_mtx) with mutex_lock_killable(&misc_mtx) > so that /dev/raw-gadget users can terminate upon SIGKILL and khungtaskd will not complain > about misc_mtx. > > Next mitigation was not to call file->f_op->open() with misc_mtx held. > Wedson worried that this approach breaks modules which call misc_deregister(), but > I think we can use this approach for modules which do not need to call misc_deregister() > given that this approach is opt-in basis. > > I also think that we can bring wait_for_device_probe() in snapshot_open() to before > lock_system_sleep(), for system_transition_mutex will not be required for waiting for > the image device to appear. If we can accept the "not to call file->f_op->open() with > misc_mtx held" mitigation, wait_for_device_probe() in snapshot_open() can be called > without locks. > > Finding universally safe timeout value is beyond what I can do for this report. > Regarding this report, I think we can lower the risk of regression if we apply > timeout for atomic_read(&probe_count) == 0 from only snapshot_open(). > Can we make below changes? > > ------------------------------------------------------------ > > drivers/base/dd.c | 14 ++++++++++++++ > drivers/char/misc.c | 4 ++++ > include/linux/device/driver.h | 1 + > include/linux/miscdevice.h | 1 + > kernel/power/user.c | 31 ++++++++++++++++++------------- > 5 files changed, 38 insertions(+), 13 deletions(-) Can you make this a patch series, it's hard to tease out what the different things are attempting to do here :( thanks, greg k-h