From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DF57C433E9 for ; Wed, 27 Jan 2021 01:51:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 748162068D for ; Wed, 27 Jan 2021 01:51:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388307AbhA0BjP (ORCPT ); Tue, 26 Jan 2021 20:39:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389203AbhAZSj5 (ORCPT ); Tue, 26 Jan 2021 13:39:57 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD3F1C061354 for ; Tue, 26 Jan 2021 10:36:10 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id h9so7317812wrr.9 for ; Tue, 26 Jan 2021 10:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Yw3RM/yk9wzBes8csZwbs5/wVqbQMigeWCray2zWeak=; b=ie2rsto3zADnlUTfWtARNuIyll2roERNJspYxOrwMT/xghOeCNGeovsPo1kCxY40ZH rIByKI3Vfv6AmHSKqVdSIXwGv9w0J2YZXsvdFGRvGLdcw5dh+XA/R0vCyAxEfvJAhJtq 46bqPKpqu3pXVDjojhTThjzM/5b+9Ux6GqDcQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Yw3RM/yk9wzBes8csZwbs5/wVqbQMigeWCray2zWeak=; b=efEF8oTcqJqbN+tM8GmN8jAdvdlQ95GHq4KIYdHtE4MByAXdaCkHysO3KuYlV/R0NR 5iOA1hIr5iFdweihnYuoG/6gOENNPvBl/Rx7G62G+LWVItU8XkVsvs7Nf4gVV4uuMI6U 3sTwCZfUtPxhS/vY18Co5HIVoD++RkvY4HHqUEXwjGn/iR673M8czevicjVxI1vv9yCX GhYAkvXiZamC+GryV/9boM/2nz5ncS/00OqTXsPV3cRqB1NDAqhjjHqCmFoRSQgwQNg5 sxivaSrfDqP8bUtZuSUP/+IuRa+m5nSMWmJLx+YKKDEAVI+0CVdnMlOPEDKMNVlxHfJK LYXw== X-Gm-Message-State: AOAM532+SkTw5sXMWbMbsuwce7R13Wh8oPxpZTSn6CYxdVwj0+u7oMXo EMQD5SaMa+SZguyuz7Kp8LVZgg== X-Google-Smtp-Source: ABdhPJxstY9iqwYrPWlri/zeLYeb1fuAmLaClTHd9h+nlUtHSMnOmK7VdpQ3UeS9xuhA+5qKdY31iA== X-Received: by 2002:a5d:554e:: with SMTP id g14mr7586403wrw.305.1611686169726; Tue, 26 Jan 2021 10:36:09 -0800 (PST) Received: from revest.zrh.corp.google.com ([2a00:79e0:42:204:deb:d0ec:3143:2380]) by smtp.gmail.com with ESMTPSA id d13sm28339354wrx.93.2021.01.26.10.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 10:36:09 -0800 (PST) From: Florent Revest To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kpsingh@chromium.org, linux-kernel@vger.kernel.org, Florent Revest , KP Singh Subject: [PATCH bpf-next v6 4/5] selftests/bpf: Use vmlinux.h in socket_cookie_prog.c Date: Tue, 26 Jan 2021 19:35:58 +0100 Message-Id: <20210126183559.1302406-4-revest@chromium.org> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog In-Reply-To: <20210126183559.1302406-1-revest@chromium.org> References: <20210126183559.1302406-1-revest@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When migrating from the bpf.h's to the vmlinux.h's definition of struct bps_sock, an interesting LLVM behavior happened. LLVM started producing two fetches of ctx->sk in the sockops program this means that the verifier could not keep track of the NULL-check on ctx->sk. Therefore, we need to extract ctx->sk in a variable before checking and dereferencing it. Acked-by: KP Singh Signed-off-by: Florent Revest --- .../testing/selftests/bpf/progs/socket_cookie_prog.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/socket_cookie_prog.c b/tools/testing/selftests/bpf/progs/socket_cookie_prog.c index 81e84be6f86d..fbd5eaf39720 100644 --- a/tools/testing/selftests/bpf/progs/socket_cookie_prog.c +++ b/tools/testing/selftests/bpf/progs/socket_cookie_prog.c @@ -1,12 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2018 Facebook -#include -#include +#include "vmlinux.h" #include #include +#define AF_INET6 10 + struct socket_cookie { __u64 cookie_key; __u32 cookie_value; @@ -41,7 +42,7 @@ int set_cookie(struct bpf_sock_addr *ctx) SEC("sockops") int update_cookie(struct bpf_sock_ops *ctx) { - struct bpf_sock *sk; + struct bpf_sock *sk = ctx->sk; struct socket_cookie *p; if (ctx->family != AF_INET6) @@ -50,10 +51,10 @@ int update_cookie(struct bpf_sock_ops *ctx) if (ctx->op != BPF_SOCK_OPS_TCP_CONNECT_CB) return 1; - if (!ctx->sk) + if (!sk) return 1; - p = bpf_sk_storage_get(&socket_cookies, ctx->sk, 0, 0); + p = bpf_sk_storage_get(&socket_cookies, sk, 0, 0); if (!p) return 1; -- 2.30.0.280.ga3ce27912f-goog