Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2907488iog; Mon, 27 Jun 2022 05:32:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uHJkRu/8LX66tWo57iwLrdxDshfYez17fdka7zRmzDNTf6nTJNgGqOjSi7j1vcp3RfP49K X-Received: by 2002:a63:f506:0:b0:3fc:962b:6e02 with SMTP id w6-20020a63f506000000b003fc962b6e02mr12724394pgh.266.1656333133659; Mon, 27 Jun 2022 05:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656333133; cv=none; d=google.com; s=arc-20160816; b=OHcD3JWymbCph/pRK2k96zfKKSu4IrH+dOAI1QfX68Xm91JHZSXRqehddkFfPx3Mcy JJqQ//54AgK6iqdfVx40jiej+/0G9RWe6+s7d7bZM3ObD2gcqr0unEvgnD+zRawpwPkr e01EUKZni7nKgjlAXigr/ce3qXxRNAClGae99oD0P1nYTM7k98QG+WHaLPUQYmA2JeuU Y6k/WppSUbgxYBoBISbAsJfsu3Ysk4wkBNHTW+D0UHU5MBRxkFn2xQB/7qvEjqdv1216 grUg8++/Tf+5s+LOPEv6AahcxokHun/mvDeXtEhaJXM1DeoUCFoHbjMr+h+slTV8Q4Oi wCMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gsWVJf+MFBFgPUnueHTTBI376tHuaQtiAGPGWtcgqYw=; b=VkXQzJI6cmKGf3X3meSHHkBdy2cfmb5uE0wYaDUlsPVAI1JmL0oY7a505wJj1d01On zT5yE75ljXdUn/OlQCRw092XUZmGWpTrFPuHiuquj1y7VtqvMUxNXo95WmTvWH1qkbNp gn+alytu0hrwu/kU/SkSlbqVhsvZmN06JgFAn/B30b5bP/AEQQlzYIrwShEKG0WZ3gr1 sI1OfG6rJPbGNZLOtQwr9vwt+lDY2JA4g7H8Ua1OssnsE465gVfM/vEJOGGBEjxo7lR/ bdbd5npNxmOS+cpfGRz+STNInHbfEnOY4Mlp/AgIJLRTBAQJ1ORAJH1JomOsmorCzTnz 1QkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Sghqqm/5"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o2-20020a170903210200b0016a162a95eesi12218529ple.147.2022.06.27.05.32.00; Mon, 27 Jun 2022 05:32:13 -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=@linuxfoundation.org header.s=korg header.b="Sghqqm/5"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237732AbiF0Lpl (ORCPT + 99 others); Mon, 27 Jun 2022 07:45:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237460AbiF0Lmx (ORCPT ); Mon, 27 Jun 2022 07:42:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F7F3E02; Mon, 27 Jun 2022 04:38:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E4B96B8111B; Mon, 27 Jun 2022 11:38:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46A7DC3411D; Mon, 27 Jun 2022 11:38:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656329895; bh=ya6NqRRRrlm7hZiwo+jdpCTe+xU8kmDhkrN5GWHursc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sghqqm/5oca0TJF5LZbsoT7WtEnKrDdDwjJvQsIZunL9yoGxbDBZpj7T/H0rUCZpx tC8udpWJIk4vHn2ru+YCWL+J970yajTd6IqLWeLxhxIbCuL8JNR4jw7Nb/JIpZDEAR kZu0HqQCnggA3C08GGrT1tmSjXzZkAERtqf5Bm3Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tyler Hicks , Christian Schoenebeck , Dominique Martinet Subject: [PATCH 5.18 016/181] 9p: fix fid refcount leak in v9fs_vfs_get_link Date: Mon, 27 Jun 2022 13:19:49 +0200 Message-Id: <20220627111945.033453940@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111944.553492442@linuxfoundation.org> References: <20220627111944.553492442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Dominique Martinet commit e5690f263208c5abce7451370b7786eb25b405eb upstream. we check for protocol version later than required, after a fid has been obtained. Just move the version check earlier. Link: https://lkml.kernel.org/r/20220612085330.1451496-3-asmadeus@codewreck.org Fixes: 6636b6dcc3db ("9p: add refcount to p9_fid struct") Cc: stable@vger.kernel.org Reviewed-by: Tyler Hicks Reviewed-by: Christian Schoenebeck Signed-off-by: Dominique Martinet Signed-off-by: Greg Kroah-Hartman --- fs/9p/vfs_inode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -1250,15 +1250,15 @@ static const char *v9fs_vfs_get_link(str return ERR_PTR(-ECHILD); v9ses = v9fs_dentry2v9ses(dentry); - fid = v9fs_fid_lookup(dentry); + if (!v9fs_proto_dotu(v9ses)) + return ERR_PTR(-EBADF); + p9_debug(P9_DEBUG_VFS, "%pd\n", dentry); + fid = v9fs_fid_lookup(dentry); if (IS_ERR(fid)) return ERR_CAST(fid); - if (!v9fs_proto_dotu(v9ses)) - return ERR_PTR(-EBADF); - st = p9_client_stat(fid); p9_client_clunk(fid); if (IS_ERR(st))