Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3329723rwa; Tue, 23 Aug 2022 02:59:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR6In16y2ikWiG00NZ+peCoFQt2U4V4BrIJEDh/gHHsXiXFIDE8Qqjcp74+57WsT/JW6GD3O X-Received: by 2002:a17:907:270a:b0:73d:721e:d057 with SMTP id w10-20020a170907270a00b0073d721ed057mr7796026ejk.501.1661248787740; Tue, 23 Aug 2022 02:59:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248787; cv=none; d=google.com; s=arc-20160816; b=v7slGTSPM54r9wNU3Ij+bRCfF2/vpjAonABfiakrfnTm43pe1bRQXG6dRMgGQYuLAP Eiopk/J4WCJsdYs4Yt7S3FK1jimpOsxFWU9/5S2OC5QVeBRrvG+g2/gdQgCn0US6ph+L wbd8iHm2f0TksUKXpwBfS7JaXvtlPbU2I3MTltkNYpEr1pG7O+fMEqD3ITAHWtfC4LcF HaXWOXs3mx5ag7WBidL0akvAy755BZ8E9pk02+wvX783285yJXKL8ZowH0ep3XLRQTNo PkOGpXJ5RUV2Dd/JaLiV3zi8GEpbPlgI5F9lwIKDLkIWYvod8ZaZ5/1HsAxflqi173FO ch3w== 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=qlOXW39zdLa8bQXk3sT8aVwyfwXWtPj1CR6mHiAZRfE=; b=O6VB/1RC1SuBSdbyq6aDiZScnlvAvlYyeg50avP9KJgAbF/dNKSwQveKTUsDDn+ibC M9T1JJcmVv/9lQjlocxQvpowHBS1rdoAtPARCL0d3wyM6yIYrkY2urWgSZIk0GbFXEti kahxUCxG6cIgttXi+sPfa7BKFmt/oNJqgptr24OGlEkcKu9rEacrwHR5uJapIbcyn4jM rgr0M3rZ/SEeTGFzoUwl2gQfduKFIzsE542tJz8yQYRXxoZOCPE+6/cjqi6jy1o08jjO YIArVwpYgYU4+A6zV2mvngwISvq/OI3g80nRIqcmVjBGXg5E6YiAVBJG8gpyJR4g+WLs fdWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="G3z/JtOE"; 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 v20-20020a056402349400b00442785a4226si2091249edc.258.2022.08.23.02.59.21; Tue, 23 Aug 2022 02:59:47 -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="G3z/JtOE"; 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 S241607AbiHWJrZ (ORCPT + 99 others); Tue, 23 Aug 2022 05:47:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238995AbiHWJnM (ORCPT ); Tue, 23 Aug 2022 05:43:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 796C29A98D; Tue, 23 Aug 2022 01:42:48 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 5DB6F61544; Tue, 23 Aug 2022 08:42:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FB2DC433B5; Tue, 23 Aug 2022 08:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244164; bh=jB3YNJsFdpWo6NSXnr57ykLaI5aOJvdDCj4JEpWaiYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G3z/JtOEaQ+ic2kImswrVPV1dJBl2+M8GU0AlLn6plH4vda35QJn9Jj7jVF9FfKKP GrYi+c6eDPTiQSuyFIyT+NOed1ACNWA52g1fSiD0JHW7b6tU+AIMBQdXo6uXghjkvU XBgz7XQz39k0qTVtCgKxNAQ4y7X1OTV2LPkx+5/0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hou Tao , Yonghong Song , Martin KaFai Lau , Alexei Starovoitov Subject: [PATCH 5.15 046/244] bpf: Acquire map uref in .init_seq_private for sock local storage map iterator Date: Tue, 23 Aug 2022 10:23:25 +0200 Message-Id: <20220823080100.596719094@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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: Hou Tao commit 3c5f6e698b5c538bbb23cd453b22e1e4922cffd8 upstream. bpf_iter_attach_map() acquires a map uref, and the uref may be released before or in the middle of iterating map elements. For example, the uref could be released in bpf_iter_detach_map() as part of bpf_link_release(), or could be released in bpf_map_put_with_uref() as part of bpf_map_release(). So acquiring an extra map uref in bpf_iter_init_sk_storage_map() and releasing it in bpf_iter_fini_sk_storage_map(). Fixes: 5ce6e77c7edf ("bpf: Implement bpf iterator for sock local storage map") Signed-off-by: Hou Tao Acked-by: Yonghong Song Acked-by: Martin KaFai Lau Link: https://lore.kernel.org/r/20220810080538.1845898-4-houtao@huaweicloud.com Signed-off-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman --- net/core/bpf_sk_storage.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/net/core/bpf_sk_storage.c +++ b/net/core/bpf_sk_storage.c @@ -865,10 +865,18 @@ static int bpf_iter_init_sk_storage_map( { struct bpf_iter_seq_sk_storage_map_info *seq_info = priv_data; + bpf_map_inc_with_uref(aux->map); seq_info->map = aux->map; return 0; } +static void bpf_iter_fini_sk_storage_map(void *priv_data) +{ + struct bpf_iter_seq_sk_storage_map_info *seq_info = priv_data; + + bpf_map_put_with_uref(seq_info->map); +} + static int bpf_iter_attach_map(struct bpf_prog *prog, union bpf_iter_link_info *linfo, struct bpf_iter_aux_info *aux) @@ -914,7 +922,7 @@ static const struct seq_operations bpf_s static const struct bpf_iter_seq_info iter_seq_info = { .seq_ops = &bpf_sk_storage_map_seq_ops, .init_seq_private = bpf_iter_init_sk_storage_map, - .fini_seq_private = NULL, + .fini_seq_private = bpf_iter_fini_sk_storage_map, .seq_priv_size = sizeof(struct bpf_iter_seq_sk_storage_map_info), };