Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp897105pxf; Wed, 7 Apr 2021 14:27:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKNymranI+v7+rqy9JbiL6uCxdouboGmb/XeAgW4SVBtXhtVYGhnKtnFUFMgygd1tX7WUL X-Received: by 2002:a17:906:8410:: with SMTP id n16mr6251498ejx.378.1617830871663; Wed, 07 Apr 2021 14:27:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617830871; cv=none; d=google.com; s=arc-20160816; b=01OPOr7OcA5KWC6IUi0CH80dZv18fNxg29osznPTs00kZnp+4VaW3TQPsHV8HcgK9y BFb2ssy5n8pkxfVXvGybD4LFZo5F3rwdnpElPgCT5+w/2e8w8IZlZHVG7IQYvCuj8KVE FdqLFgmV3CZ3K2rPIvdFDWrjtAwdSyldZM171binHMndhAQsTcqqODLAP90xNOdnzpjA HzlMby9UXcw43OPvVynNQpPE4LuvlJX6s4qzCIDqoe0K1iG9CSHV7ctTcr0T3hPCzvF+ kA8ZtockMPip03XPecwuBbtqeggGJY1WFdEP3CWagYKAiSnDVyHs0ZPxMxkU2Dg/on8G gyoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=e55XxdhFEquyLB2Ir8ZHzShBhWe4g5kf5ai240p48C8=; b=zQv1+LDPZFVpxuNigXhqn0DWZXmnS8AZqA5b6fWPEj7NvLOgdul3/weTRHrrB0Cv8+ R3136tiAEcr/UhWGqtMAlyFN+zze2r6nQm2cPwFdQsPqq4ZsbTd1noqDZEXXDT6S+ep0 FN9NdICVbJfcsNKmMisG30PAdks/hTUTh97q40NcazH4zFFlp7ThERGOleEFTu8OamHn QwycL4y6y/k53JFgT7MvuP4RtcGbd/2Ql+zTD52G/3FaxQ96jaGCUd+f8pTAEAlMdwzv OoDnRIXk0zeMHMCsrr6YYCNpahKVvDFX4z5C2dsybq/PsMfr/d1Uqv83Royv1Cvggcuj c+pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EZqkyiQ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s10si6315630edw.351.2021.04.07.14.27.28; Wed, 07 Apr 2021 14:27:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EZqkyiQ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353940AbhDGPvM (ORCPT + 99 others); Wed, 7 Apr 2021 11:51:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27284 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353908AbhDGPuv (ORCPT ); Wed, 7 Apr 2021 11:50:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617810641; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=e55XxdhFEquyLB2Ir8ZHzShBhWe4g5kf5ai240p48C8=; b=EZqkyiQ8/YWM2cebSFIRsqO2R4EOdFCAp0Clp2knzxd+FTgVMwRipVgxPkz3PiCE4p+7jk B2L0h0fuUIjp1DZkmt9I29Kzle5ZLWa6wPFeqN2sk7bzfPfBf/uiHY/s6gOEDRC0ejdJyP 8/JV7QMdxBC+owHCPPHhNin3FSTjxZw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-245-5_T2zrWdOB2lBb81PkAixw-1; Wed, 07 Apr 2021 11:50:39 -0400 X-MC-Unique: 5_T2zrWdOB2lBb81PkAixw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2C0E81425A; Wed, 7 Apr 2021 15:50:37 +0000 (UTC) Received: from horse.redhat.com (ovpn-117-29.rdu2.redhat.com [10.10.117.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0993F1042A66; Wed, 7 Apr 2021 15:50:32 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 6DF1122054F; Wed, 7 Apr 2021 11:50:31 -0400 (EDT) Date: Wed, 7 Apr 2021 11:50:31 -0400 From: Vivek Goyal To: Aditya Pakki Cc: Stefan Hajnoczi , Miklos Szeredi , virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fuse: Avoid potential use after free Message-ID: <20210407155031.GA1014852@redhat.com> References: <20210406235332.2206460-1-pakki001@umn.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210406235332.2206460-1-pakki001@umn.edu> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 06, 2021 at 06:53:32PM -0500, Aditya Pakki wrote: > In virtio_fs_get_tree, after fm is freed, it is again freed in case > s_root is NULL and virtio_fs_fill_super() returns an error. To avoid > a double free, set fm to NULL. > > Signed-off-by: Aditya Pakki > --- > fs/fuse/virtio_fs.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c > index 4ee6f734ba83..a7484c1539bf 100644 > --- a/fs/fuse/virtio_fs.c > +++ b/fs/fuse/virtio_fs.c > @@ -1447,6 +1447,7 @@ static int virtio_fs_get_tree(struct fs_context *fsc) > if (fsc->s_fs_info) { > fuse_conn_put(fc); > kfree(fm); > + fm = NULL; I think both the code paths are mutually exclusive and that's why we don't double free it. sget_fc(), can either return existing super block which is already initialized, or it can create a new super block which need to initialize further. If if get an existing super block, in that case fs->s_fs_info will still be set and we need to free fm (as we did not use it). But in that case this super block is already initialized so sb->s_root should be non-null and we will not call virtio_fs_fill_super() on this. And hence we will not get into kfree(fm) again. Same applies to fuse_conn_put(fc) call as well. So I think this patch is not needed. I think sget_fc() semantics are not obvious and that confuses the reader of the code. Thanks Vivek > } > if (IS_ERR(sb)) > return PTR_ERR(sb); > -- > 2.25.1 >