Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2136217rdb; Tue, 3 Oct 2023 11:15:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOguHjRU0+rtjsuP0QywIP9NkF3oo4Cx+7PePnitxnRFoBrGcRhzquiHjPjJYgN+F0XW0w X-Received: by 2002:a17:90b:4b4b:b0:276:79b6:8bd6 with SMTP id mi11-20020a17090b4b4b00b0027679b68bd6mr124434pjb.15.1696356957165; Tue, 03 Oct 2023 11:15:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696356957; cv=none; d=google.com; s=arc-20160816; b=YOgA/KMJXcIh9AbQzTLIYT5J4vzgPK5E3MkeSURzSfaD0Xc0ALMT74jOZhRPfxez9A kyXZV5KLm5+VhOaW03ZCyc9BLGXyqC5AZ64+HLWcd65CStfXTpV7I0z9STtpGSll2YZH T2KdF0SlhTU57T+p0s/YL3Ak7vnvOQ1DzWsvPyJBfuggnPSRvMLtC09gwX/TC8LFRGxz jXZ/d646j2f/VdGDhuYc9nkaAj7wF75h0G81T08r2vcg6vSYXFTgEyRyvocKgm0VBB3n N0yHLUhMs51fSSoDgBmrI+qFHvdFRivZlcuqRUuzLzp+EKWtfmsrUoKbh8U3p9wi/BoD oMgg== 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=7D3mbu8+f86gaPTmTRzTqW6VjzonZ7FDhl1jo3gyzMA=; fh=JRoLHFGeB+1PYsNAI0nUFU4cXm9/UKbLfQUY0Mco/J4=; b=MStcHXEP+ha8c62+XJK7LQKS3o1YyugE8SLrOqHF+kiNGsmY7OIuWJthVeSYGi66og VD+wmeR/HYbGasWmViSqYLbyd+xKj5Z2xcTwj5lY+c/LYfqQPR6DoKbdf9eQlnUyO9ss 8L+ByhKCTkzCfpWbyEbZgCqUYIEm5zNbK+MCTsazCL7oful7XnEXJs27l4Hr/uWN1Lwj Y9l1TcDFPDEn1MpX5q4pSL7WaI+p8ge/Qz6KTqunGHMUNoncGLB8Dgy2dOgKFGCHASdO FvxI4TH4jrfUuAdf3rOGa1C8cjMN34S1aR6adJJxB/zHs7YEUQM2n59apLPM1QTYy9qw GTWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tGTl4pkM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id p7-20020a17090a868700b002791d79bbf9si10240754pjn.187.2023.10.03.11.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:15:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tGTl4pkM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9A814807FCC5; Tue, 3 Oct 2023 11:15:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240734AbjJCSPA (ORCPT + 99 others); Tue, 3 Oct 2023 14:15:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230291AbjJCSO7 (ORCPT ); Tue, 3 Oct 2023 14:14:59 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F2FDAF; Tue, 3 Oct 2023 11:14:55 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBF6AC433C9; Tue, 3 Oct 2023 18:14:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1696356895; bh=8GoDX/lQWvZX83VR+w8ZgUvPrV/g+cmMeP0xEH3Sras=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tGTl4pkMUq/U7oa/9mlZKnVyDUGV0B/kyreObHCMvVsUMKXABrHa6mAbU43zLnRq/ PO2W31KFoJH7edCCkm5XH4zVT1jjJgtx1FCqVwq+e04D4RVcPH3VgDixwS2BmIlq6R ugFgnPMzX57NqHHwGRRElwJSZcFrk80KNW8cTUHA= Date: Tue, 3 Oct 2023 20:14:52 +0200 From: Greg Kroah-Hartman To: Lee Jones Cc: linux-kernel@vger.kernel.org, Daniel Starke , Fedor Pchelkin , Jiri Slaby , linux-serial@vger.kernel.org, syzbot+5f47a8cea6a12b77a876@syzkaller.appspotmail.com Subject: Re: [PATCH 1/1] tty: n_gsm: Avoid sleeping during .write() whilst atomic Message-ID: <2023100320-immorally-outboard-573a@gregkh> References: <20231003170020.830242-1-lee@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231003170020.830242-1-lee@kernel.org> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 03 Oct 2023 11:15:07 -0700 (PDT) On Tue, Oct 03, 2023 at 06:00:20PM +0100, Lee Jones wrote: > The important part of the call stack being: > > gsmld_write() # Takes a lock and disables IRQs > con_write() > console_lock() Wait, why is the n_gsm line discipline being used for a console? What hardware/protocol wants this to happen? gsm I thought was for a very specific type of device, not a console. As per: https://www.kernel.org/doc/html/v5.9/driver-api/serial/n_gsm.html this is a specific modem protocol, why is con_write() being called? > __might_sleep() > __might_resched() # Complains that IRQs are disabled > > To fix this, let's ensure mutual exclusion by using a protected shared > variable (busy) instead. We'll use the current locking mechanism to > protect it, but ensure that the locks are released and IRQs re-enabled > by the time we transit further down the call chain which may sleep. > > Cc: Daniel Starke > Cc: Fedor Pchelkin > Cc: Jiri Slaby > Cc: Greg Kroah-Hartman > Cc: linux-serial@vger.kernel.org > Reported-by: syzbot+5f47a8cea6a12b77a876@syzkaller.appspotmail.com > Signed-off-by: Lee Jones > --- > drivers/tty/n_gsm.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c > index 1f3aba607cd51..b83a97d58381f 100644 > --- a/drivers/tty/n_gsm.c > +++ b/drivers/tty/n_gsm.c > @@ -270,6 +270,7 @@ struct gsm_mux { > struct tty_struct *tty; /* The tty our ldisc is bound to */ > spinlock_t lock; > struct mutex mutex; > + bool busy; > unsigned int num; > struct kref ref; > > @@ -3253,6 +3254,7 @@ static struct gsm_mux *gsm_alloc_mux(void) > gsm->dead = true; /* Avoid early tty opens */ > gsm->wait_config = false; /* Disabled */ > gsm->keep_alive = 0; /* Disabled */ > + gsm->busy = false; > > /* Store the instance to the mux array or abort if no space is > * available. > @@ -3718,11 +3720,21 @@ static ssize_t gsmld_write(struct tty_struct *tty, struct file *file, > > ret = -ENOBUFS; > spin_lock_irqsave(&gsm->tx_lock, flags); > + if (gsm->busy) { > + spin_unlock_irqrestore(&gsm->tx_lock, flags); > + return -EBUSY; So you just "busted" the re-entrant call chain here, are you sure this is ok for this protocl? Can it handle -EBUSY? Daniel, any thoughts? And Lee, you really don't have this hardware, right? So why are you dealing with bug reports for it? :) thanks, greg k-h