Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2930028rwb; Mon, 15 Aug 2022 14:15:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR4VK8hWRF/NRs6GBZb4YExf7BDNQZU1HoxW7lPnoXb5Z74Y2DzSWxlN+6T3CjBAodZ2iV9E X-Received: by 2002:a17:906:cc13:b0:730:97a4:8fbe with SMTP id ml19-20020a170906cc1300b0073097a48fbemr11025939ejb.412.1660598151781; Mon, 15 Aug 2022 14:15:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660598151; cv=none; d=google.com; s=arc-20160816; b=DvccDqziLyeminvCTatVd7iID3xWhujWbsXmtrYYWLr8u/wDJ/QAUVT/JAY7h5jgug NLgWVe8Oj05848B3HDemVuBAh7v3Oy34JeklsSEcxkHC1wUFiKie+R2HrDwTOq1MnGSw FgJKJQ6C1SE2hvQeOv23NOO8LRCdMyNHhbL+msy/my3hRCNxSSTIG8d1LIlHUA1Jc1/n A/k6jAWJYhpRIbGMaCk15uraR5J9S3x3X3qEMTS45UGIsVgKGaxJComUWWIQmve3x/G+ h7f3CwVxXYRAgbQjRcXhdhQcdYe+Z8n1phOmNyH3y2YfBr/CACAXHFkdrVWqFv655SBL zQig== 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=AccdApb/puKY/yekRwbuM+GYv4cHjlB+ZHTT/vzXg/U=; b=AZRnRVC6WY5gfydootJ9UY/TkR+eCEVo/zBfdSJbPhhTrsO4VW27yc4ajAowDDR5kP gymMut9Ygqwk1hdg8rGaz738Ln3BWcfkD2l8p6R7+H9hp9M6wwh73pQBCJ0ulSn0yYCO 9AIT0Pkz/uNmngU4wdN8yP3SCRhmOpkaGzVczEymag0qvdtrRGXl2biEI5VbHPCxMG8S HAb+Mrq+2u6h4tUozHdDisYc9BqpeFKmipVp3ocX6qXCs9nv77Zvvgm0EInLKvq82N7a 8ooa1cWi4qif+4Dsh/EjEBfo0A8DW914B8pHl8MRicAocMfxdsvQKE7s0iAVh/Z5LNUu 7sFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=V1fKiarp; 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 dt18-20020a170907729200b00734be0ce32esi9543717ejc.688.2022.08.15.14.15.23; Mon, 15 Aug 2022 14:15:51 -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=V1fKiarp; 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 S231334AbiHOVIv (ORCPT + 99 others); Mon, 15 Aug 2022 17:08:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344445AbiHOVDt (ORCPT ); Mon, 15 Aug 2022 17:03:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A677DD3EC8; Mon, 15 Aug 2022 12:14:41 -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 8371860F68; Mon, 15 Aug 2022 19:14:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7562DC433C1; Mon, 15 Aug 2022 19:14:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590879; bh=zv4DZZibKAMRI0gVGHC/jrX5f2LnrYxkNA82LOX0cq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V1fKiarpTVHVFxy/EDPdR+zoGyTrZe4MaVv0M2q4TcdvuCUATzEBm/MAE+7jzNEUG q1OyXPSzIIJ1+1vifRq8OzBhEAllE41AZJrwXFCF0C8Xlg9zKA48xZT2c6sVPmILtV cdascGXjbVN7PC2FmALSb1yMTluT0HXXxB70cMh8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?J=C3=B6rn-Thorben=20Hinz?= , Andrii Nakryiko , Jakub Sitnicki , Martin KaFai Lau , John Fastabend , Sasha Levin Subject: [PATCH 5.18 0369/1095] selftests/bpf: Fix rare segfault in sock_fields prog test Date: Mon, 15 Aug 2022 19:56:08 +0200 Message-Id: <20220815180444.981359376@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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: Jörn-Thorben Hinz [ Upstream commit 6dc7a0baf1a70b7d22662d38481824c14ddd80c5 ] test_sock_fields__detach() got called with a null pointer here when one of the CHECKs or ASSERTs up to the test_sock_fields__open_and_load() call resulted in a jump to the "done" label. A skeletons *__detach() is not safe to call with a null pointer, though. This led to a segfault. Go the easy route and only call test_sock_fields__destroy() which is null-pointer safe and includes detaching. Came across this while looking[1] to introduce the usage of bpf_tcp_helpers.h (included in progs/test_sock_fields.c) together with vmlinux.h. [1] https://lore.kernel.org/bpf/629bc069dd807d7ac646f836e9dca28bbc1108e2.camel@mailbox.tu-berlin.de/ Fixes: 8f50f16ff39d ("selftests/bpf: Extend verifier and bpf_sock tests for dst_port loads") Signed-off-by: Jörn-Thorben Hinz Signed-off-by: Andrii Nakryiko Reviewed-by: Jakub Sitnicki Reviewed-by: Martin KaFai Lau Acked-by: John Fastabend Link: https://lore.kernel.org/bpf/20220621070116.307221-1-jthinz@mailbox.tu-berlin.de Signed-off-by: Sasha Levin --- tools/testing/selftests/bpf/prog_tests/sock_fields.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sock_fields.c b/tools/testing/selftests/bpf/prog_tests/sock_fields.c index 9d211b5c22c4..7d23166c77af 100644 --- a/tools/testing/selftests/bpf/prog_tests/sock_fields.c +++ b/tools/testing/selftests/bpf/prog_tests/sock_fields.c @@ -394,7 +394,6 @@ void serial_test_sock_fields(void) test(); done: - test_sock_fields__detach(skel); test_sock_fields__destroy(skel); if (child_cg_fd >= 0) close(child_cg_fd); -- 2.35.1