Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp9145441rwb; Thu, 24 Nov 2022 08:38:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf6knI0C7tUzEBr6TtspYCp+nB1+x68rsMtCdEZJQy2D0ufaT3UA3klW22Bf3RszmttWFA2J X-Received: by 2002:a05:6a00:4509:b0:562:641b:c1b2 with SMTP id cw9-20020a056a00450900b00562641bc1b2mr18203779pfb.8.1669307908366; Thu, 24 Nov 2022 08:38:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669307908; cv=none; d=google.com; s=arc-20160816; b=HJInhk7tw9lAocqf896DvGYJSYx4An6Gm1iMkbLGvMqCFPcfo48OrpZmb4zkhzENFI p15zCsu/zyS8+oAHQXMVh4B6QP2f+3tAbeCa0NhrbqoKeQX+Xr9timEU4Jlou4Pw9tDY xnW6aSOBq9t0V8+Renp6Br8290olX7E4Xz7EEd7EYKds29Quk5VPMeODHwf1nGB1ofgw xgYzO7QFT3TuzfPJQp5qvLOAet5BA+ldNCB7PL6lVx0E0In72nYlJjUEUs0DJmi0+kXl +CHJap+brqu2suwDb3VfBsY2fI6b5TCGZKuYyuTknY0dX/d6PJDAi2RBCf6UaKmMJRr9 lTpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=miyEx8Lvn6qBvvvvpZMBad8XUo7oHhn8LKm5H35p0iY=; b=FOHSa37iAGmZKP2w9mTJejExsSiegwBNNNrwyGC1VnivP4e6OeBWdVL3ug7IxnrsL2 WF0tIRB7W8lkBhWD/66joQz56OxbB9641obG65ou0gTuFbR2Vh+AI62Avh0TwUGwX5eo VSzzPaKXFuVHj4b0RFIakZzHhKsLogix+WNVdEp139vCrIjFHlS2c1WvIfIrK/AouFhB Q8HWy30PFVFj5YhCKqfU08Dnm0pqshZz7OjcqE3wNtARuUaupVjolvUwevfXv/RY6yJb z1gfGAvMV/FmhZSET2r9L/QsMqoo1FmbuiJQ1kPfAzJXdXY8IQJcH7HhOnYqzO3Dmf6m 1GoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=au0bv3es; 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=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i5-20020aa78d85000000b00569a7731a99si1411120pfr.326.2022.11.24.08.38.16; Thu, 24 Nov 2022 08:38:28 -0800 (PST) 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=@linux.org.uk header.s=zeniv-20220401 header.b=au0bv3es; 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=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229624AbiKXQQF (ORCPT + 86 others); Thu, 24 Nov 2022 11:16:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbiKXQQE (ORCPT ); Thu, 24 Nov 2022 11:16:04 -0500 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC9BD5ADF9; Thu, 24 Nov 2022 08:16:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=miyEx8Lvn6qBvvvvpZMBad8XUo7oHhn8LKm5H35p0iY=; b=au0bv3esIGNCwbpleIoD/gmreN V3Z0IPip15p0H9Xw1rTsoyl0PAF6DVHZl4pLDzbcogCNMVYDD923dL0b0OxfHhJBgTUabM31lr3Go ZrDKiCSk4YNsdL2Hv+MukyGKSMi2Ep0RlokzXjefT0BfKhd8Nr4vgmxh5L6sCH06HMaKHBWQnwKzY 3fA3NsYSYu1aDRIgSUiGH3JtimB34qHvBjG5S4gCTHeVC6fGKiaKB7b5DadqKv4nSNOIP8xJy7kci 4rn2ArI8X+YGsqQWlxi3xXXa7FPpvsVyALkgvL+m+90JrjAZjJk5KyI4spECoGtLipVEpo/QlnLJo PhGe5M5A==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1oyEsz-006TPU-3B; Thu, 24 Nov 2022 16:15:38 +0000 Date: Thu, 24 Nov 2022 16:15:37 +0000 From: Al Viro To: asmadeus@codewreck.org Cc: Wang Hai , ericvh@gmail.com, lucho@ionkov.net, linux_oss@crudebyte.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH net] net/9p: Fix a potential socket leak in p9_socket_open Message-ID: References: <20221124081005.66579-1-wanghai38@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE 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 On Thu, Nov 24, 2022 at 06:15:54PM +0900, asmadeus@codewreck.org wrote: > Wang Hai wrote on Thu, Nov 24, 2022 at 04:10:05PM +0800: > > Both p9_fd_create_tcp() and p9_fd_create_unix() will call > > p9_socket_open(). If the creation of p9_trans_fd fails, > > p9_fd_create_tcp() and p9_fd_create_unix() will return an > > error directly instead of releasing the cscoket, which will > > (typo, socket or csocket -- I'll fix this on applying) > > > result in a socket leak. > > > > This patch adds sock_release() to fix the leak issue. > > Thanks, it looks good to me. > A bit confusing that sock_alloc_files() calls sock_release() itself on > failure, but that means this one's safe at least... sock_alloc_file() unconditionally consumes socket reference; either it is transferred to new struct file it returns, or it's dropped. Makes for simpler logics in callers... FWIW, ACKed-by: Al Viro on the leak fix.