Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1611949rwr; Thu, 27 Apr 2023 22:14:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ50uVlRMG4TJ4BE4IsPZaoScD9sb8nQn+ZZkmS7vuoJg+k+bZYpCskAIjIfg+NYWSiDxRd8 X-Received: by 2002:a05:6a21:6706:b0:ec:6039:f76f with SMTP id wh6-20020a056a21670600b000ec6039f76fmr4470002pzb.11.1682658842981; Thu, 27 Apr 2023 22:14:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682658842; cv=none; d=google.com; s=arc-20160816; b=bkPq2Q8AynHkClNpEZq831rQW9VdKd52QOo/0/0dHHPfrzRFTWCtby1zrOkn/9o+Lv nlAc9OgGTGqKv2ybCx8dXLwxCrWHbWuJ0Mja3TyR2mJA5kqExvsL9VNuvboW/GtjuFSt iSgIFD6n7h0YgtJrgfXrnzJvTfHFhwqsL5wprVFHmcbTCTjKx+5d+R/3zfU/0WubIcw2 1doMwCpB3sHi3SwVkZcRmDFntnSyhiPCZoKxTiJArd8TPUdI4y73DHSTKl1BgqEMy6Ih S2IYXpnzVL3ObnUjcQHC1CxG6zCx6mW+jCAmWklLudls3GCOGBprjCcXmBKI0bbpnUuZ JscA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=lnYDs5O+lpcMObRSDdsk44BWcyPiz0zcPcKC4GaBYVY=; b=fx6Je809pnjixKDwJYXXrvIrbtWimsbmeTA6gzDPkZwoEWuPryjDjaiKJKJMEvjev2 mtM1vS6Db0S7ixFc3GlVOgTptRWLLPGmI0IfxfY0nPHsIY96fwLXpFCX1oGCJyxP2FY/ TQP127CrdJv1sGGnfD4YBB/ZlJm1ZLedmPcRbwCQC6gUuexRuOzRD9P0saCXV8MNRBkV hT/hx46GL7knqAfAPjUr5vRAJRyb53dTAY84CKsNFSlgXHsKwrLnhoQlTCdGUAUum4ok auzNZHIPvaopMEsVFOn/27Wi7ag+VUbj6Ld+yj3iQ+5Ns/AkHo60U8Sh+BXmL+bGOJyy OpBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="gkFTg/cX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020a634304000000b0051ef3e20a83si19546788pga.312.2023.04.27.22.13.49; Thu, 27 Apr 2023 22:14:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="gkFTg/cX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345012AbjD1FAr (ORCPT + 99 others); Fri, 28 Apr 2023 01:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229570AbjD1FAq (ORCPT ); Fri, 28 Apr 2023 01:00:46 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A50E269F; Thu, 27 Apr 2023 22:00:43 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2a8ba5f1d6bso91398621fa.2; Thu, 27 Apr 2023 22:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682658040; x=1685250040; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lnYDs5O+lpcMObRSDdsk44BWcyPiz0zcPcKC4GaBYVY=; b=gkFTg/cXXXB+sw6EP6iP4NIjEbu5k0eqG3zHM9oe+HyO14Jmr5iHR57egC5GaboEzK Hrc6VKxGFeEZhkUXk0kY2ljpPUmejNxNRfSSCbwKs0Fz7xSg+/q6T/PP1XuuecuxJx/k TdDmvePdTrvCh74I66JSqz32RpTp4eQbygwDLaejhs0gbQiINS8uH76u8pD5FmX39F1E DAEuhYObU3RLwkrzsJpEJoXt7o306gvomsiHoUwnmvNNF/O6MsTvzclyApxtlWGQRuw5 ZuJshfit9NRD351q6yXyBFgf18ziafsIWcpMHhxa1yEW8dfxKIIfz3W49QVMLT31cOnf tzAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682658040; x=1685250040; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lnYDs5O+lpcMObRSDdsk44BWcyPiz0zcPcKC4GaBYVY=; b=PSIf0zLtLSUnZRhc5EviXqZYx/SjZ7lY/lUqApNU0wbayg7S3Hnzw/wmA7FVBzWCEy bmED+o+rlw8SdHTLVzHVjZjj2OT9dnR86tgLh/uNHYiTEXgwu1rYozqjO3q6FMHoKDoV G801S8N87B/G8waK1SFcxS6kM0QczrI8UQXhqhyC2Q/KaQK86Kl3BYVhMp2uhWaSWRQ1 nkXrGcyJiePh9hMnEMFt0Y6f5mgjEdTExW7qonECAMVr0ZTe+r9TVZ0kjopn0oykscuX rKOwsSS7oMe4PBy3Is31904AyX9Wcdsm2AcvTMKgRiQUJEQ7Gg/w08OAse2QU6IN5796 GT6w== X-Gm-Message-State: AC+VfDwl4Re07lS2hCmzyA8WO7YtM9c1TEEtiCj7gkHdlR8l/3WCRqv8 TmuMXoKGcgznjcOeeYEJmpy5MZ4kiooD3OXfW5ybYuBEbVm2re5K X-Received: by 2002:a2e:9987:0:b0:2a8:a5b8:185a with SMTP id w7-20020a2e9987000000b002a8a5b8185amr1236090lji.10.1682658039733; Thu, 27 Apr 2023 22:00:39 -0700 (PDT) MIME-Version: 1.0 References: <20230323013655.366-1-k1rh4.lee@gmail.com> <2023042702-shuffling-tweet-d9f6@gregkh> In-Reply-To: <2023042702-shuffling-tweet-d9f6@gregkh> From: sangsup lee Date: Fri, 28 Apr 2023 14:00:04 +0900 Message-ID: Subject: Re: [PATCH v2] misc: fastrpc: Fix a Use after-free-bug by race condition To: Greg Kroah-Hartman Cc: Srinivas Kandagatla , Amol Maheshwari , Arnd Bergmann , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I apologize for recognizing the email in the TOP POST format. I missed the comment in the previous email. 2023=EB=85=84 4=EC=9B=94 27=EC=9D=BC (=EB=AA=A9) =EC=98=A4=ED=9B=84 6:52, G= reg Kroah-Hartman =EB=8B=98=EC=9D=B4 =EC=9E=91= =EC=84=B1: > > On Thu, Apr 27, 2023 at 06:29:16PM +0900, sangsup lee wrote: > > Is there any comment for this issue? > > What issue? > > > (reference: https://www.spinics.net/lists/kernel/msg4731408.html) > > Please use lore.kernel.org links, we have no control over any other > random email archive . > > And the above link just points to this proposed patch. > > > > > > > 2023=EB=85=84 3=EC=9B=94 23=EC=9D=BC (=EB=AA=A9) =EC=98=A4=EC=A0=84 10:= 37, Sangsup Lee =EB=8B=98=EC=9D=B4 =EC=9E=91=EC=84=B1: > > > > > > From: Sangsup lee > > > > > > This patch adds mutex_lock for fixing an Use-after-free bug. > > > fastrpc_req_munmap_impl can be called concurrently in multi-threded e= nvironments. > > > The buf which is allocated by list_for_each_safe can be used after an= other thread frees it. > > How was this tested? > I was unable to configure the environment in which this code is running. Therefore, I could not go through dynamic testing for the related issue. However, I found vulnerabilities in similar types of functions in other drivers in the mobile environment, so I think this code is also problematic. > > > > > > Signed-off-by: Sangsup lee > > > --- > > > V1 -> V2: moving the locking to ioctl. > > > > > > drivers/misc/fastrpc.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c > > > index 93ebd174d848..aa1cf0e9f4ed 100644 > > > --- a/drivers/misc/fastrpc.c > > > +++ b/drivers/misc/fastrpc.c > > > @@ -1901,7 +1901,9 @@ static long fastrpc_device_ioctl(struct file *f= ile, unsigned int cmd, > > > err =3D fastrpc_req_mmap(fl, argp); > > > break; > > > case FASTRPC_IOCTL_MUNMAP: > > > + mutex_lock(&fl->mutex); > > > err =3D fastrpc_req_munmap(fl, argp); > > > + mutex_unlock(&fl->mutex); > > Are you sure you can call this function with the lock? If so, why isn't > the mmap ioctl also locked? I am convinced that FASTRPC_IOCTL_MUNMAP can lead to a race condition bug. However, as I mentioned in patch v1, I am not an expert in fastrpc. I worried about the side effects of the code I suggested. So, I asked you to recommend which code to use, and this is the code that was recommended to me. And I didn't check the mmap function because I couldn't find a bug in mmap. > > thanks, > > greg k-h