Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1129097rdb; Wed, 24 Jan 2024 05:55:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6ZEqWuXY4xI89H3FvvA/BF6FBHlVqW2g07jszqLXLt7ULJmUydFVzf+AEFIR6sYm5SAzf X-Received: by 2002:a05:6a21:1f29:b0:19a:5a1a:241b with SMTP id ry41-20020a056a211f2900b0019a5a1a241bmr809037pzb.106.1706104550394; Wed, 24 Jan 2024 05:55:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706104550; cv=pass; d=google.com; s=arc-20160816; b=cvnRANhb44brzJ175sIGAG6fCsvAtWn6mEOOd0rctdh2i8xjo9jQSLBZJFTTH0cRdv kyuJp+Avk6gm8stDQm/PCHXUENWzcAUDYOzaGzz6skWtr/eRN8zN0elNqkPaNYoV8okP YWQohqblWc6Q1XRPs/vsYeKzY2ijhKNYJW4YNBTanA8cWbfpykj1SEJsxR4BErMa9XsZ Ave3HO+wbIlpG4+vo7V5L1Fc7wDEqEM7tsBRWxDS4RKUMtKSbTtrbXOKZG4R+Mc4mhVi AduE42gGRNuRE7zksjgBVPkNNLBYCfWhFAlMeMuJRTaghElh55VBWpm9Cq+9zMQnKH/O ym0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=BMNksOhFYflsdA/lL2YcasBOnaXyHvU7y5aeV/DjwfE=; fh=LpUqJAeUGkHBEOF+hV6HxWjndd8LHu0Yx/QZHm0wAQE=; b=TmkLuOjVPKx0VTNxk8xacOk9od521rYZwRoOeWEBobdGTnCo9SzfC8KGzSWKmNciXZ dLvCR7HbZteca337tWf8FprmCy0QiMm+xFyUoO9AkFLUtILW+Xicnt+bxMG4VoMEkbQP nQOlGSUbG5V0V1Vz4S76yfWYOPFfg9+hZWJBwpsm6epyQxJu8kJd36zksPNzUrp5Sgps jk3/Y+KKC42cYucGHE48E1japooGTGzVw45toy8EcMgEzD40ZxszpMOxl2Z4pI7CgQAe ZDCozoufBF/lCfDPj33jKDhsvYqkKEJUCASFhRz8RApNPEYAnS2qSIAdq5tjpT+/3Vgp /W9A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="bFw/9swF"; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-37055-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37055-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id o7-20020a634e47000000b005cdf9a34830si11667796pgl.588.2024.01.24.05.55.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 05:55:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37055-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="bFw/9swF"; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-37055-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37055-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C533FB221A0 for ; Wed, 24 Jan 2024 13:14:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83D2377F09; Wed, 24 Jan 2024 13:14:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="bFw/9swF" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5988CA69; Wed, 24 Jan 2024 13:14:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706102074; cv=none; b=lE0fVJ1uqOlVgRZOM89+ScNkY0//MfAKbXdItrLpqs7oX+oTVu0Xn3rl80BpAYx5WcG3UURVFiRjYoM1dNxhtXh5hdacc/ZjmhSL5rEsQ0fu0V4v2ZdxhxXRueMsmtsK0D7oFYfMb5OEpFkvwvCKmxB2K8iwntZdt5aRwqMM0IU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706102074; c=relaxed/simple; bh=koDgMrcjogLVfiLz/IfmsWpml4ucZzU/i7sdgvu3aAQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SLKxtX5bwcNzXy+57VwTSdNHQ5GWFWBW0xALPo+byzrVWoZOKPzGytcWePPgtSCoez/RfaEfzuUfKH6WqOXs2u7u5uIYf1tfjRLFeQk3yQ686WTeaKBafhdiimF/C07mug1F/7w76V0MZAkNEsF3KQyVNmNQLH8m/dVEgHY9CKo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bFw/9swF; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17517C433F1; Wed, 24 Jan 2024 13:14:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1706102074; bh=koDgMrcjogLVfiLz/IfmsWpml4ucZzU/i7sdgvu3aAQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bFw/9swF4yJbajb5ujAMqD5qk1RQ2eMITTdGpWSrYOi7h3ltC2ZnNpXUtHKauO8dj vBUyrF4W3C7gnnL4FbfIRWeHjbr2n+64EOsIXeYaQB8dNWBqBc9TL7o7BOjePIetRx Ml1LOps2VBY6+/vqKgb0lER33yQRmrVBvMLF06cQ= Date: Wed, 24 Jan 2024 05:14:33 -0800 From: Greg Kroah-Hartman To: Tetsuo Handa Cc: Jiri Slaby , syzbot , syzkaller-bugs@googlegroups.com, Andrew Morton , "Starke, Daniel" , Lee Jones , Fedor Pchelkin , linux-kernel@vger.kernel.org, linux-serial Subject: Re: [PATCH] tty: n_gsm: restrict tty devices to attach Message-ID: <2024012418-passover-habitual-5a92@gregkh> References: <00000000000039f237060f354ef7@google.com> <83414cb6-df16-4b6d-92e3-d54d22ba26cc@I-love.SAKURA.ne.jp> <9cd9d3eb-418f-44cc-afcf-7283d51252d6@I-love.SAKURA.ne.jp> <82aa07d4-13ac-4b1d-80cd-0970c71752a5@kernel.org> <7dc23b9d-5120-4966-b47b-fcabe270d498@I-love.SAKURA.ne.jp> <42d17017-1d30-4c54-9c28-9d9ba2494e07@I-love.SAKURA.ne.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <42d17017-1d30-4c54-9c28-9d9ba2494e07@I-love.SAKURA.ne.jp> On Wed, Jan 24, 2024 at 07:06:04PM +0900, Tetsuo Handa wrote: > syzbot is reporting sleep in atomic context, for gsmld_write() is calling > con_write() with spinlock held and IRQs disabled. > > Since n_gsm is designed to be used for serial port, reject attaching to > virtual consoles and PTY devices, by checking tty's device major/minor > numbers at gsmld_open(). > > Link: https://www.kernel.org/doc/html/v6.7/driver-api/tty/n_gsm.html > Reported-by: syzbot+06fa1063cca8163ea541@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=06fa1063cca8163ea541 > Signed-off-by: Tetsuo Handa > --- > 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 4036566febcb..14581483af78 100644 > --- a/drivers/tty/n_gsm.c > +++ b/drivers/tty/n_gsm.c > @@ -3623,6 +3623,7 @@ static void gsmld_close(struct tty_struct *tty) > static int gsmld_open(struct tty_struct *tty) > { > struct gsm_mux *gsm; > + int major; > > if (!capable(CAP_NET_ADMIN)) > return -EPERM; > @@ -3630,6 +3631,17 @@ static int gsmld_open(struct tty_struct *tty) > if (tty->ops->write == NULL) > return -EINVAL; > > + major = tty->driver->major; > + /* Reject Virtual consoles */ > + if (major == 4 && tty->driver->minor_start == 1) > + return -EINVAL; > + /* Reject Unix98 PTY masters/slaves */ > + if (major >= 128 && major <= 143) > + return -EINVAL; > + /* Reject BSD PTY masters/slaves */ > + if (major >= 2 && major <= 3) > + return -EINVAL; That is a lot of hard-coded magic numbers, why aren't these defined anywhere? But really, this is only for fuzz testers, why can't they just not ever bind this to a console? Why do we have to have these checks in the kernel to prevent userspace from doing dumb things that no real userspace will ever do? thanks, greg k-h