Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1843036lqp; Mon, 15 Apr 2024 21:49:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUTIX1yW3HwcBHKJHulLJ88YEKw6uBJNE7HfLPA4h9BgPWD7qeMlNBUZimfmUwUprpT1ZR7KO2RuJktVLe7if3FXUWa8CNU7WAlAZH88g== X-Google-Smtp-Source: AGHT+IFVGXwy8mYcDcA/i7ROnP0TfQ+XHfh9skErvn480TQjF7qA9f0Ffp7aqDZ1VwcJX0Gwon5X X-Received: by 2002:a17:902:ce0e:b0:1e0:115c:e03c with SMTP id k14-20020a170902ce0e00b001e0115ce03cmr12251543plg.53.1713242994293; Mon, 15 Apr 2024 21:49:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713242994; cv=pass; d=google.com; s=arc-20160816; b=GSO2mQOeVFJCZelmZqaDZFtKLk0ZcTi0Xq1ayg7qugqVuboSQPkzSALgibKX3+1r4t A9+PgC8imFEfxlV1xNuHtasiU2Q+evOik8y95gSrDy5czA53nBh/3BwiqXGNLx2T5vvq q6x/Aa9qGhNPCPtFDaAkvPOFmqwczCp/pjFm0/T2To8mYmD+ndZ7UvXXesBgCFc/5mSM 2hhHbhHwMVVUO/rBpeQFowYtXH3ZCr2YWa+YX7Op/3d2lJZ5C3tidF35c7b89P9cMLvr ZkuPdD2iaHJm0meWyOQesCzPgdQUQcdxl6H0A6HrUpD2Ze2CtOMSoR5mZdLMJRnPwSwZ LXLA== 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=uCmuISeiWqY6WxKhtJ3e1M5Nk8bJDfctGeN/vvGJRgs=; fh=PsVnr0s3kHNPNkx23PVvzWuo1dwYu9fuB/iVZ4odfDw=; b=gPbHUOuKopRMvLJ8Wqjxyeuxha4Jga2AIQca6BCZaWGs0sD259CDmALburyBFf3gB0 U8yuYkbeJzBAryMyyyHjBYm6qFVa5Ltj7qE/jNFkzuZAH9zz/YfECJZjVXidPOU59h4M Ulm1jTU21+2Gxy7i3Bk0HRC651CqHVFvdiVSZ8HipC5xNuNaHnUOokFV59C6YWE61QwW oKBQfcYMd+v8FOlmBEhu0k0BCJAGYyhM/7gzUDlNJ+xQP9EJyFLk/vEnXhr0u9RlZApP bdEX1qxL6RiVDsP7JVqvMvNSfPN3QMuFWJoST5pcnrbasfNcwWD9sHKeNArhe+bMV36q tu1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TSIOHs1T; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-146241-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146241-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.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 o3-20020a170902d4c300b001e5c06b32f7si6511815plg.441.2024.04.15.21.49.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 21:49:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146241-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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TSIOHs1T; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-146241-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146241-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EED43284FAF for ; Tue, 16 Apr 2024 04:49:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DBCB381BD; Tue, 16 Apr 2024 04:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="TSIOHs1T" 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 64B991642B for ; Tue, 16 Apr 2024 04:49:48 +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=1713242988; cv=none; b=gOVI8Q8SOMSBULBgsumpmPYYlat54DbyPNk453o5J+Zm1AokghUcSzH3h755kerGSL2ttVCP+4GcAgR27FO7zCXSQtFLBYTMXuoqUsvCmq4HJc69qJA3YMArDt/qXqNKaZHW9OPwQL0w6IPy3IAipUvnv2qKW/8uhmsnF29twb8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713242988; c=relaxed/simple; bh=aHDljlWTmUinNNo0sb6wTvxH2kECa12PPEoAt9mZth0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HbDIYKJyj6Zg/S5zDwa00/Mnf6pmHx6kxoyqer0071RZJ1PpYCZ2p+hDHk6fuS17mymKvoMH4bswLNvr/SvDTReKI+s6Ul8A4lG0wr1Yp7+v9XxaMM/7K9RwS4eT579oXVl6exIi1w7oDT3UFdlnjT3rBo0L/NOCdEis2Qom0j8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TSIOHs1T; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 789F6C113CE; Tue, 16 Apr 2024 04:49:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1713242988; bh=aHDljlWTmUinNNo0sb6wTvxH2kECa12PPEoAt9mZth0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TSIOHs1Tb3oLK0FC+dgPNoBUMjt45XzbszoTX1iqwX7dSALlE1T/PSBsHVx3+Mov9 QJiL1veeM0fnyNKIGBM5NbwrCjmoAmdgvpBoDypBx01wiRzLQu8qxgPq4nZOZJP0Tu CtWmSeXNIfsK/iV7J7V+Byj/spCAfz7j+oU+llRg= Date: Tue, 16 Apr 2024 06:49:43 +0200 From: Greg KH To: sicong Cc: johan@kernel.org, elder@kernel.org, greybus-dev@lists.linaro.org, linux-kernel@vger.kernel.org Subject: Re: Bug report: greybus/interface.c: use-after-free bug in gb_interface_release due to race condition Message-ID: <2024041624-oxford-sabbath-9f6a@gregkh> References: <280ee5e5.4936.18ee4d93bae.Coremail.congei42@163.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: <280ee5e5.4936.18ee4d93bae.Coremail.congei42@163.com> On Tue, Apr 16, 2024 at 11:00:25AM +0800, sicong wrote: > greybus/interface.c: use-after-free bug in gb_interface_release due to > race condition. > > In gb_interface_create, &intf->mode_switch_completion is bound with > gb_interface_mode_switch_work. Then it will be started by > gb_interface_request_mode_switch. Here is the code. > if (!queue_work(system_long_wq, &intf->mode_switch_work)) { > ... > } > > If we call gb_interface_release to make cleanup, there may be an > unfinished work. This function will call kfree to free the object > "intf". However, if gb_interface_mode_switch_work is scheduled to > run after kfree, it may cause use-after-free error as > gb_interface_mode_switch_work will use the object "intf". > The possible execution flow that may lead to the issue is as follows: > > CPU0 CPU1 > > | gb_interface_create > | gb_interface_request_mode_switch > gb_interface_release | > kfree(intf) (free) | > | gb_interface_mode_switch_work > | mutex_lock(&intf->mutex) (use) > > This bug may be fixed by adding the following code before kfree. > cancel_work_sync(&intf->mode_switch_work); Wonderful, please submit a patch with this information and we will be glad to review it. thanks, greg k-h