Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1177557lqt; Sat, 20 Apr 2024 04:13:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCULR94Q1AyUywWxglHeGy2gxUTj6KsaUOPe65wepWZDoWmLp1BB+oCvSEUyY0JqVV64CNIvoidf3+GRNqgnCZX2/svYfTcXvaACytam/w== X-Google-Smtp-Source: AGHT+IGC4Y+bFSAjHZ/ieJut9Ln74apmNcVGY+0ChrKl8rDrFby6YFoLR8Ir3EDXBrbrPcxY1eaD X-Received: by 2002:a05:6a00:2181:b0:6ea:ab45:6605 with SMTP id h1-20020a056a00218100b006eaab456605mr5305419pfi.4.1713611583403; Sat, 20 Apr 2024 04:13:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713611583; cv=pass; d=google.com; s=arc-20160816; b=rLVA/Tnu95CNDSnHPPsM0qLH1FZQ+oisZitbXNgaxdxq6rF5pe5kEFVPVl7VnF+0hx qiwq/8Gpv7dHgl4BfweYNrQJT2f+VMdkXFOymEZeDIESwMjAJo1jP3tqsiYp1kJ9Oqmg DEWRLNTJpdTgBcuIqBaCKcl66Pze/gk6Gpsq5Qow8jx7169qxpSPxu3f8Y5gSoWprjir OVx03ZP/XNTL8CX+fR5jBlsVWbrvb4v8PalFrGQDL9YrjYTcsyxm8CCwpVGzz5JxcnXh VGL35Z806FWXgYyM1OBzfJ3gdeHdzqpUqezJxzPJfdBXigyu4zDVfdvbM4wPCY9k6I2Y 3Otw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:subject:from:cc:to:content-language :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id; bh=3IuK4ZZDxhfRetDoaogu7gmUW6GXcxePmgcLq2sTCNU=; fh=cEKkC/VZEF0IQM2uVxFlztM8sqVwkt3FZkm1/DVyASA=; b=CAko2lHntnMKm2qGYnKKwaEBnde6nuosOmlZRDsLyka7+NlPvbmXN3WyIFBvHBxPRM MsAeeUINYRxd6KmsjG8yyBsSVdK72wMMKK/A20VDB05Ydou5SxZtbHot+W8AK1x+ZkmS c/esO8Zupw26xG/GHd2SbUlrDLLaav8TFAIN3jo6dYkSkdKS8e7+fpsJr/Vi5VcmzQd3 wCT70bByp2IflqYS3REp3TgJyhVDi9+pXVVH8yLT1Mw2MbceQAOOe1HaDgY9yWe/57Vc vTbjkePEf3zHKBR4jqs8pC9QIQrcm9TAzWEdSH63S4rqjnOTnCOJUCLqQPld7I9gVV1P WvEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=i-love.sakura.ne.jp); spf=pass (google.com: domain of linux-kernel+bounces-152240-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152240-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id le11-20020a056a004fcb00b006ed14fed3a9si4832807pfb.218.2024.04.20.04.13.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Apr 2024 04:13:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152240-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=i-love.sakura.ne.jp); spf=pass (google.com: domain of linux-kernel+bounces-152240-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152240-linux.lists.archive=gmail.com@vger.kernel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8D3FE281CFF for ; Sat, 20 Apr 2024 11:13:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 57CE329421; Sat, 20 Apr 2024 11:12:56 +0000 (UTC) Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) (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 84678DDD9; Sat, 20 Apr 2024 11:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.181.97.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713611575; cv=none; b=QI+PPjI200WE0ge0BBaD0NkQ2K+L1V48VmyG+UyN+IbraYsomoBUnSsmE6ixgNuwJNcbJiXmuv+I6cERThqh+74ny3n3tuTCeAbEnzRUI5/tUeeWFLYfbHvBaRHz+SFSJqBbqyoJSHq07HaLmLK5tYQrkRng3gtTpAVmBGSjORU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713611575; c=relaxed/simple; bh=zWl1BQf481DzJyk/natZZmOl4ZV7BIUTnSgzALdmI6U=; h=Message-ID:Date:MIME-Version:To:Cc:From:Subject:Content-Type; b=YujOuJQgik2FilFcBJjhNOSAvGj1GDRh09kU8PSqBAhQHpSP5pXb/XiCVEcC7iR6TvKJ5HBmEUzsh7QSbEVvwWwYNPX7QG6Lda/NTCsh70UWHqrM4/X3E6UA2uSJeYOCdMjl+/d8kRL4qVeCPLkeG5xsRatlsf4KgkHS8tVSDk4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp; spf=pass smtp.mailfrom=I-love.SAKURA.ne.jp; arc=none smtp.client-ip=202.181.97.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=I-love.SAKURA.ne.jp Received: from fsav111.sakura.ne.jp (fsav111.sakura.ne.jp [27.133.134.238]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 43KBCWj2079237; Sat, 20 Apr 2024 20:12:32 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav111.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav111.sakura.ne.jp); Sat, 20 Apr 2024 20:12:32 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav111.sakura.ne.jp) Received: from [192.168.1.6] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 43KBCWif079233 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Sat, 20 Apr 2024 20:12:32 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: Date: Sat, 20 Apr 2024 20:12:32 +0900 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Greg Kroah-Hartman , Jiri Slaby , Andrew Morton , "Starke, Daniel" , LKML Cc: linux-security-module , Linus Torvalds From: Tetsuo Handa Subject: [PATCH v2] tty: n_gsm: restrict tty devices to attach Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 [1], reject attaching to virtual consoles and PTY devices, by checking tty's device major/minor numbers at gsmld_open(). Starke, Daniel commented Our application of this protocol is only with specific modems to enable circuit switched operation (handling calls, selecting/querying networks, etc.) while doing packet switched communication (i.e. IP traffic over PPP). The protocol was developed for such use cases. at [2], but it seems that nobody can define allow list for device numbers where this protocol should accept. Therefore, this patch defines deny list for device numbers. Greg Kroah-Hartman is not happy with use of hard-coded magic numbers [3], but I don't think we want to update include/uapi/linux/major.h and add include/uapi/linux/minor.h just for fixing this bug. Link: https://www.kernel.org/doc/html/v6.8/driver-api/tty/n_gsm.html [1] Link: https://lkml.kernel.org/r/DB9PR10MB588170E923A6ED8B3D6D9613E0CBA@DB9PR10MB5881.EURPRD10.PROD.OUTLOOK.COM [2] Link: https://lkml.kernel.org/r/2024020615-stir-dragster-aeb6@gregkh [3] Reported-by: syzbot Closes: https://syzkaller.appspot.com/bug?extid=dbac96d8e73b61aa559c Signed-off-by: Tetsuo Handa --- Adding LSM ML to CC list in order to ask for comments if Greg again complained that we don't want to add sanity check on the kernel side. I agree that we should fix fuzzers if fuzzers are writing random data to /dev/mem or /dev/kmem . But for example https://lkml.kernel.org/r/CAADnVQJQvcZOA_BbFxPqNyRbMdKTBSMnf=cKvW7NJ8LxxP54sA@mail.gmail.com demonstrates that developers try to fix bugs on the kernel side rather than tell fuzzers not to do artificial things. 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; + /* Attach our ldisc data */ gsm = gsm_alloc_mux(); if (gsm == NULL) -- 2.18.4