Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp720039pxx; Wed, 28 Oct 2020 15:29:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwq2RsuXB77DyoQm4osSN5i6QhrB0SoatkYIhSy+5Dpz4R2H6Eqfk+7PSWYXkPWxSym/+ju X-Received: by 2002:a05:6402:2070:: with SMTP id bd16mr1120805edb.358.1603924192739; Wed, 28 Oct 2020 15:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603924192; cv=none; d=google.com; s=arc-20160816; b=HqRMsGCFHKDJzjG/57egeoBdav4MoMYP7r+IK8OvoeYerlOObdDh45v7CHLg7ubOUm J+WS94Ispdrgv4rMtYzMnyJ7dtbySmOQtPhrDW+0OGLLDOijBFgxvXh6DODN0dblpqiT +4vQJ5shVduEz1FZLk++EzQfCQQBbg7F51cyCYUO6Z90atvs69bIFEIizwxtxDDpI/Vt ocy9M439EhycbFqrLmVtt0oVPRKvUB+TyP1oSdxKVndbqRXkj7SpEHlez1yqBYckadnX qfG1XBq3jvXl/7kEKiruNsWgfSEbqcrdDFB8Yq9U+rnQfFJSP/m4Rv0ro1UjEBhx/EYZ iHLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=bUyX17ha/cWDYBq2yGKRRjbmdVNBIkx7o4pI6dqo+1k=; b=Zq+19YWLxlLM2/ixVdLRfkqRJHVmXQGO05XOsi5guNcIm1Jb2G7iTloMRzyJp32ejo DjtU+y7CVFsYyHIBcQ3cNRO75irFVyp+DBDNPtii7W5VCEEULp4OxRA9onEV3dIvKHkr zTPpLoMujejcfvj+heYg4QUz8w6zWtIS7h3ii8nu2+DGBGjTi6BBz8lvyeWD8C3mEaxn 8vITM+I9+OsOfyVasOJutrUSHfKl9wQXqc0eILI6KFdVnRhvBXCh2XfyIrx+pOgj8Oqg nWO0iFvpeUeCiIBdZHr2A00cQmWdZXkNCpfTCC/IH4hrsKUWKn71BF+Zut1rf6P8AggH veCg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si466207ejd.269.2020.10.28.15.29.31; Wed, 28 Oct 2020 15:29:52 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733259AbgJ1W1X (ORCPT + 99 others); Wed, 28 Oct 2020 18:27:23 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:6570 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733245AbgJ1W1W (ORCPT ); Wed, 28 Oct 2020 18:27:22 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CLdGt2GKFzhckW; Wed, 28 Oct 2020 14:00:54 +0800 (CST) Received: from [127.0.0.1] (10.174.176.238) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 28 Oct 2020 14:00:45 +0800 Subject: Re: [PATCH] pipe: fix potential inode leak in create_pipe_files() To: Al Viro CC: , "linux-kernel@vger.kernel.org" , References: <779f767d-c08b-0c03-198e-06270100d529@huawei.com> <20201028035453.GI3576660@ZenIV.linux.org.uk> From: Zhiqiang Liu Message-ID: <5b121dd9-7752-2ea0-ef8b-63ba2a3c3966@huawei.com> Date: Wed, 28 Oct 2020 14:00:45 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20201028035453.GI3576660@ZenIV.linux.org.uk> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.176.238] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/10/28 11:54, Al Viro wrote: > On Wed, Oct 28, 2020 at 11:03:52AM +0800, Zhiqiang Liu wrote: >> >> In create_pipe_files(), if alloc_file_clone() fails, we will call >> put_pipe_info to release pipe, and call fput() to release f. >> However, we donot call iput() to free inode. > > Huh? Have you actually tried to trigger that failure exit? > >> Signed-off-by: Zhiqiang Liu >> Signed-off-by: Feilong Lin >> --- >> fs/pipe.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/fs/pipe.c b/fs/pipe.c >> index 0ac197658a2d..8856607fde65 100644 >> --- a/fs/pipe.c >> +++ b/fs/pipe.c >> @@ -924,6 +924,7 @@ int create_pipe_files(struct file **res, int flags) >> if (IS_ERR(res[0])) { >> put_pipe_info(inode, inode->i_pipe); >> fput(f); >> + iput(inode); >> return PTR_ERR(res[0]); > > No. That inode is created with refcount 1. If alloc_file_pseudo() > succeeds, the reference we'd been holding has been transferred into > dentry allocated by alloc_file_pseudo() (and attached to f). >>From that point on we do *NOT* own a reference to inode and no > subsequent failure exits have any business releasing it. > > In particular, alloc_file_clone() DOES NOT create extra references > to inode, whether it succeeds or fails. Dropping the reference > to f will take care of everything. > > If you tried to trigger that failure exit with your patch applied, > you would've seen double iput(), as soon as you return from sys_pipe() > to userland and task_work is processed (which is where the real > destructor of struct file will happen). > > NAK. > Thanks for your patient response. Learned a lot from your reply. Please ignore the patch. > . >