Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp773358rdb; Thu, 22 Feb 2024 21:58:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVTFP2M7EbNrqGTnRCTRqnlPbQ2DQUhAIGwhQuLsaVcIcnBm29zZ2m8ARyMiRHfdM4auh3doQ8BDI3WqZdqBg05bVK5IPxe3+W4MdHQlA== X-Google-Smtp-Source: AGHT+IHdtr6NoodNvKG8gvYPPA0j1gB8QxDLWWg/zKAf3nI+wpE/VHnFUnZfnX3eysIwvPyp/CjD X-Received: by 2002:a17:903:1cf:b0:1dc:1379:213b with SMTP id e15-20020a17090301cf00b001dc1379213bmr1549702plh.35.1708667909660; Thu, 22 Feb 2024 21:58:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708667909; cv=pass; d=google.com; s=arc-20160816; b=mkr3eKrHdgb6aApjwqvF7PblCnhNykIEkRbn5tU5kb3t0rnswQ1FOYMfTsSG/WLwV6 iQmsqQg1ZvrwF7I2TGe5Z3ORG+nvQfnUciOLdkKZQS7M6nyd8lgCvXvefGCqTxudajHl nneTU+e++PkoDIWGMXd5JFTZu4j1IcQ0NrRcR1d2EHo2/LfMBPaHbqqvaep1jnaZcBW/ t2geCT2nl4mt1/QJDx5Uh0Pwef0hI5NLlswbaI8n2Fhu6RqAMVNVJ+xGg3TH/s5mFxVq zVOnVEdOiCSxOt7qKVLaBFi4g7fpyoope0OJEEYYLUCYDj2xJtbQoPwjh1/QD2uDS/NB TwhQ== 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=S6xgVMe7ZlkEqVuUgD1khaxHrGiWnPd37VqSuHVZNnQ=; fh=yD8s/a9FDX3Dr/tNYPmHFn0SloYhdcgGTwO7NSGBkDY=; b=MkpD9dFpjQJWg13GGSfCiCaKmF2iGTVw9qoQusI5b0mIY9oEmCwLVSJElu1AH+Ish8 pypVY3DJoS6KguOSO8MMTX2bX+A4MQjGooeJtUYcGyKC3DdbL101RIxNMrJpUODuIoN0 ZNZl1UJ9d8Nn4dESSbbkevZ/HObFj4NGeEHpnu2Z2Psk1gZts2q8DXwfpNJH0xwAfKla LrpLsH+ywWGIjqfTTcXaXJz2C8SFAkxWP6I+P36Z60wV+dvtDfvyFEpfunEHZadiaUiG vSGT7n4X8HWI3bLNHE70+4/7wP9ncIDE0+qu2NRyhUUcE3qwOy77CPdK+DYr2JUeBms9 QX5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vPBJQQBx; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-77813-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77813-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. [147.75.48.161]) by mx.google.com with ESMTPS id d18-20020a170902ced200b001dbcf7ec8aesi10658897plg.1.2024.02.22.21.58.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 21:58:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77813-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vPBJQQBx; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-77813-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77813-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 A82FAB25926 for ; Fri, 23 Feb 2024 05:58:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE028125AD; Fri, 23 Feb 2024 05:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vPBJQQBx" 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 D0CA9B66B; Fri, 23 Feb 2024 05:58:12 +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=1708667893; cv=none; b=eCFiufiPR/Go5NUeJNbAiGZRqgQYhawFnnIpCT10zhwM8jGtocytStvbM5QNx/d7cuuhvKBka6hJtq1AxhT/9d9gI8kFPWfpzf2VrAxHHIi+cvMeZT3so5XkqS3mWDJ37B7t+WHmLh77caepXx9xl4Imqkus6TxwsiYI0XsFTTA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708667893; c=relaxed/simple; bh=w48BAtHZfqUxdEwvSQENgtIIBjNl/cSlxICoYJeN8zE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m32v8w4sqejqzRAukDJCQHT84QwamZdwl87WBted7UQOwq6wDO3/2HIZvNGkAtDpsyYNjRa2m+I9Dhy1Fx/G4sX0YvM/hUwtUfhYD46c8QKt3QU1apS0bGF67lADfE1aB9meYPCsCS0IqNuTu08211H/txnmisfHoJ4kEjfR5fE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vPBJQQBx; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBED2C433C7; Fri, 23 Feb 2024 05:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708667892; bh=w48BAtHZfqUxdEwvSQENgtIIBjNl/cSlxICoYJeN8zE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vPBJQQBx5DXXY9Az3Fv/QfVnoRMcmnzr5ZuyRMCAmZXcW1yaRbnhbvbUtWI3xbyip hxs5oWGAYvGLvrjztzCbPgYJYC3EyEOG9EelpgBabYKu8PO99fNycklijdMpt6ExLG 981cJNYE3BeDDgzphf4eQeFEyZdLUlgXzBd3Zu0A= Date: Fri, 23 Feb 2024 06:58:09 +0100 From: Greg KH To: Selvarasu Ganesan Cc: brauner@kernel.org, axboe@kernel.dk, jack@suse.cz, jlayton@kernel.org, keescook@chromium.org, peter@korsgaard.com, hayama@lineo.co.jp, dmantipov@yandex.ru, quic_linyyuan@quicinc.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, quic_ppratap@quicinc.com, quic_wcheng@quicinc.com, quic_jackp@quicinc.com Subject: Re: [PATCH] usb: gadget: f_fs: Fix NULL pointer dereference in ffs_epfile_async_io_complete() Message-ID: <2024022302-routine-schematic-b4fd@gregkh> References: <20240223054809.2379-1-quic_selvaras@quicinc.com> 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: <20240223054809.2379-1-quic_selvaras@quicinc.com> On Thu, Feb 22, 2024 at 09:48:09PM -0800, Selvarasu Ganesan wrote: > In scenarios of continuous and parallel usage of multiple FFS interfaces > and concurrent adb operations (e.g., adb root, adb reboot), there's a > chance that ffs_epfile_async_io_complete() might be processed after > ffs_epfile_release(). This could lead to a NULL pointer dereference of > ffs when accessing the ffs pointer in ffs_epfile_async_io_complete(), as > ffs is freed as part of ffs_epfile_release(). This epfile release is > part of file operation and is triggered when user space daemons restart > themselves or a reboot is initiated. > > Fix this issue by adding a NULL pointer check for ffs in > ffs_epfile_async_io_complete(). > > [ 9981.393115] Unable to handle kernel NULL pointer dereference at virtual address 00000000000001e0 > [ 9981.402854] Mem abort info: > ... > [ 9981.532540] Hardware name: Qualcomm Technologies, > [ 9981.540579] pstate: 204000c5 (nzCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--) > [ 9981.548438] pc : ffs_epfile_async_io_complete+0x38/0x4c > [ 9981.554529] lr : usb_gadget_giveback_request+0x30/0xd0 > ... > [ 9981.645057] Call trace: > [ 9981.648282] ffs_epfile_async_io_complete+0x38/0x4c > [ 9981.654004] usb_gadget_giveback_request+0x30/0xd0 > [ 9981.659637] dwc3_gadget_endpoint_trbs_complete+0x1a8/0x48c > [ 9981.666074] dwc3_process_event_entry+0x378/0x648 > [ 9981.671622] dwc3_process_event_buf+0x6c/0x288 > [ 9981.676903] dwc3_thread_interrupt+0x3c/0x68 > [ 9981.682003] irq_thread_fn+0x2c/0x8c > [ 9981.686388] irq_thread+0x198/0x2ac > [ 9981.690685] kthread+0x154/0x218 > [ 9981.694717] ret_from_fork+0x10/0x20 > > Signed-off-by: Selvarasu Ganesan What commit id does this fix? Should it go to stable kernels? > --- > drivers/usb/gadget/function/f_fs.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c > index be3851cffb73..d8c8e88628f9 100644 > --- a/drivers/usb/gadget/function/f_fs.c > +++ b/drivers/usb/gadget/function/f_fs.c > @@ -849,7 +849,9 @@ static void ffs_epfile_async_io_complete(struct usb_ep *_ep, > usb_ep_free_request(_ep, req); > > INIT_WORK(&io_data->work, ffs_user_copy_worker); > - queue_work(ffs->io_completion_wq, &io_data->work); > + > + if (ffs && ffs->io_completion_wq) > + queue_work(ffs->io_completion_wq, &io_data->work); What happens if ffs->io_compleation_wq goes away right after you test it but before you call queue_work()? Where is the locking here to prevent that? thanks, greg k-h