Received: by 2002:a05:7208:3188:b0:7e:5202:c8b4 with SMTP id r8csp817438rbd; Fri, 23 Feb 2024 04:42:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW8iskdQ1LnauBwt2zY/9Fz+s+MNdPzVYs8CEVBcyx87nnMWAOqbaBCMBGi7doZ0d684x44KKpbeAOVspGb/kdJa3mnzBXmfvTfI2yS5g== X-Google-Smtp-Source: AGHT+IFr6BWqBtFRcSarKF3aM/IVfBRxQiRNlHMjk6cA6wh2M+BFkbh6E6rP+4Bx3MEuj/GuhZhO X-Received: by 2002:a0c:f3cd:0:b0:68f:a308:bb4f with SMTP id f13-20020a0cf3cd000000b0068fa308bb4fmr1772970qvm.2.1708692153385; Fri, 23 Feb 2024 04:42:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708692153; cv=pass; d=google.com; s=arc-20160816; b=wX3BWoO4lSsi+Tvi2IE8iFMmoa7O4mDFc/HBLSvvy26vPedmZX2Qv/Oga3rKHhGht+ z7eCkJlqxP05WMga/TK3Y12CAnzx6eBtvV9v723KMiIk1HVpkjJFe3QjQfTwoKbk31pU y2Spenj3J+3iGbJZZOFTUTw6YSXDf0mfU7pi8d/I4+75DMDSYJgez+CWzJu9ykVKMiR0 eZcIOUZbeGKo5bp5LrImaz1oxCy8ZF82Dwoxfe8HI6VD5TI1eM+A4g+kkJcX46RMfJv9 kcDRd2xW1CHE8QeyV2/AQp41RrySTQKLkSn/KYP0kgZgodpWFh02F+iGL2ATPwgSdYLo n1Fg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JrxE0516wcGhCxBDHMApJALVHJEIusHQYExHsp8sSH8=; fh=yD8s/a9FDX3Dr/tNYPmHFn0SloYhdcgGTwO7NSGBkDY=; b=Fr9TL5RhrGBimzqaxsL3SnIRbUHuILrw+biz6KslZuKqAycTV59WNhKg3iXisRRhnZ Qw2r+h8nnlLGwpm2W2z8jwiTSev26+4h694Ds/mnqsbO6121h+xrVu2Gf9pikc5AT3A5 qk10DmKOEWAxPq/J+75NS/TcWNl6ygnnbIU5ERRBlOAu1U5j4lGLeLP4TL1yyNfXqtaW /UXdBcyTb6A9/ZC9wpmkgzyo81dzpiETdPQmVJMHDwX1Fg5SbkV+GeEjUdF2HxUo21li yLQiEqabV5sqvuerkxiKGKFoslsZ3yafNtqw/DmZP8e/yxB3rj21qrYMlAXsuSgMgNuJ MrbQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QvIIF0yO; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-78312-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78312-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id kl29-20020a056214519d00b0068c3ca90f97si14737934qvb.564.2024.02.23.04.42.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 04:42:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78312-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QvIIF0yO; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-78312-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78312-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 24AC61C215EF for ; Fri, 23 Feb 2024 12:42:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73B477CF21; Fri, 23 Feb 2024 12:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="QvIIF0yO" 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 893BB14A97; Fri, 23 Feb 2024 12:40:27 +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=1708692027; cv=none; b=aud+Pbf1jQbuQLy3KWtLN16YEeuetRAjBfHj7W6v5XFBHagGvVr6NVSIPuRWUolQA8Ovwg9Oc3GHE92UwHoKIXw7biDZ2XB5VDtnfl1b+JnTcOdTA5MYKyRN8HYus+QQ/dwC2JIPqmhVNMREqK0ErJD+qNbnheFK37+vwl94emo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708692027; c=relaxed/simple; bh=KKUuXezB/G+ILZzSTILOSQmE/Cbf7JN8aDFNpOwtadw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fRVYvob2/RbvZC6FCA/Rz+msTIozkETsF7BV42bWR+lCsHPOoWbt5W9Ci6sHfJzuum6txTCIlrAj3974ycECmIhCFVs1a3gWCEl1J7D11ZI+QCbaSk7ZQ2t90NMQcVDEdXI/34/xptTxmkC+hvpHtkjNtam6cDegPwRFgz7lSAc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QvIIF0yO; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94E2CC433F1; Fri, 23 Feb 2024 12:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708692027; bh=KKUuXezB/G+ILZzSTILOSQmE/Cbf7JN8aDFNpOwtadw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QvIIF0yOS7qDRmS7ZybUiXbnP9VzNjS1e91aZB3N2uZWsjsjRbCdh2Y7NDOrHKYFW qcP5UhSjxl3dhU+t3gqpqvDZ46bm8R644L3c7pAdxOz5BxYkh9WspEjqJVyii5ZDKU jNX4Sdk2YEsjvRBTfxkT6SaZVfVcZZB3s/pevq9E= Date: Fri, 23 Feb 2024 13:40:24 +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: <2024022350-rescuer-stretch-71e8@gregkh> References: <20240223054809.2379-1-quic_selvaras@quicinc.com> <2024022302-routine-schematic-b4fd@gregkh> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Fri, Feb 23, 2024 at 05:05:59PM +0530, Selvarasu Ganesan wrote: > > On 2/23/2024 11:28 AM, Greg KH wrote: > > 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? > > Fixes: 2e4c7553cd6f9 ("usb: gadget: f_fs: add aio support"). Yes it's > required to propagate to stable kernel as well. Great, when you resend the next version, please include both proper tags. > > > --- > > > 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 > > Hi Greg, > > Thank you for your feedback. I understand your concern about the > potential race condition with ffs->io_completion_wq. I’m considering > introducing a lock to protect this section of the code, but I wanted to > get your opinion on this. > In the f_fs.c driver, there are pre-existing locks. Would it be suitable to > utilize these locks, or do you suggest the creation of a new lock > specifically for ffs->io_completion_wq? We anticipate a performance impact > if we use the existing lock, as it might be held by different > threads. What are your thoughts on this?" Test it out yourself and see what works best! thanks, greg k-h