From patchwork Wed Nov 4 16:44:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: KP Singh X-Patchwork-Id: 11881543 X-Patchwork-Delegate: bpf@iogearbox.net 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=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 12201C2D0A3 for ; Wed, 4 Nov 2020 16:45:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF37E206ED for ; Wed, 4 Nov 2020 16:45:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AzK9AwEi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731282AbgKDQpH (ORCPT ); Wed, 4 Nov 2020 11:45:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731278AbgKDQpG (ORCPT ); Wed, 4 Nov 2020 11:45:06 -0500 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D3E3C061A4A for ; Wed, 4 Nov 2020 08:45:05 -0800 (PST) Received: by mail-ed1-x542.google.com with SMTP id a71so17765086edf.9 for ; Wed, 04 Nov 2020 08:45:05 -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=wMcFW95G8fkznbcNMh9DZ4j06RhSQWUhozGzIcGrvhA=; b=AzK9AwEiZGPwNuaksb7TrzVo3oLp27gs6X2tWZWKAAdhUSayUtg+IPB5CZyHe5r/L3 G78VEb+sk8NvHGssLIYBQ/TJt8nxr5eJETrF2Q/fIySbAxOUzE+9QrF0ULVGcumYH5E/ BX0RcYOpFLW9P+oMjEbVSUMjNt8HH/LHRBcHQ= 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=wMcFW95G8fkznbcNMh9DZ4j06RhSQWUhozGzIcGrvhA=; b=UcgkFrebwSZgLRlMnlYeKTADZ239UJcR1MNM2snBZlRPZby8QzxqlUmdVlOLhCTDJ3 wDKkf70zj/m6lAGxQ9NE3lJzb1PTITi2Q9I01EtdtOQHkD7h3pp7Jfl9gKwfRvszBgPZ XmDl/KsD56MJiWfXth77TNRTj/u3m0Emd7IwlotJF98OsHBzZOfPqyfdxgiiuWQRc457 E7BdK94V0M05JfiQlzMXDn6ey0HdYMN83LVvFLl/TXxF5ODl293bXdPH9XllBCw+R3t9 5MSVDPLKJan1RR2DRkCflSZy2ElDBJjTuKLdBu4wTJMw+he/ICiPJV1lN9xMfGi+5/0s F2LA== X-Gm-Message-State: AOAM532hK2lC0kp2PYZdUzONDm1Vb0A6/7bzDFUu3RVwAHdzIWhLl0u2 Z4d0foNul2XPyOdLApRKyVdZFw== X-Google-Smtp-Source: ABdhPJzSKwTyVZdRVqM1mnMbGuvRqhJWY7oplUcrB0XsB+T7ceykFWSne+hcim3fhXxF63WqMjWCew== X-Received: by 2002:a50:bf4b:: with SMTP id g11mr20694706edk.170.1604508303992; Wed, 04 Nov 2020 08:45:03 -0800 (PST) Received: from kpsingh.zrh.corp.google.com ([81.6.44.51]) by smtp.gmail.com with ESMTPSA id g20sm1283551ejz.88.2020.11.04.08.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 08:45:03 -0800 (PST) From: KP Singh To: linux-kernel@vger.kernel.org, bpf@vger.kernel.org Cc: Song Liu , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Paul Turner , Jann Horn , Hao Luo Subject: [PATCH bpf-next v3 6/9] bpf: Fix tests for local_storage Date: Wed, 4 Nov 2020 17:44:50 +0100 Message-Id: <20201104164453.74390-7-kpsingh@chromium.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201104164453.74390-1-kpsingh@chromium.org> References: <20201104164453.74390-1-kpsingh@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: KP Singh The {inode,sk}_storage_result checking if the correct value was retrieved was being clobbered unconditionally by the return value of the bpf_{inode,sk}_storage_delete call. Also, consistently use the newly added BPF_LOCAL_STORAGE_GET_F_CREATE flag. Acked-by: Song Liu Fixes: cd324d7abb3d ("bpf: Add selftests for local_storage") Signed-off-by: KP Singh --- .../selftests/bpf/progs/local_storage.c | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/local_storage.c b/tools/testing/selftests/bpf/progs/local_storage.c index 0758ba229ae0..09529e33be98 100644 --- a/tools/testing/selftests/bpf/progs/local_storage.c +++ b/tools/testing/selftests/bpf/progs/local_storage.c @@ -58,20 +58,22 @@ int BPF_PROG(unlink_hook, struct inode *dir, struct dentry *victim) { __u32 pid = bpf_get_current_pid_tgid() >> 32; struct dummy_storage *storage; + int err; if (pid != monitored_pid) return 0; storage = bpf_inode_storage_get(&inode_storage_map, victim->d_inode, 0, - BPF_SK_STORAGE_GET_F_CREATE); + BPF_LOCAL_STORAGE_GET_F_CREATE); if (!storage) return 0; - if (storage->value == DUMMY_STORAGE_VALUE) + if (storage->value != DUMMY_STORAGE_VALUE) inode_storage_result = -1; - inode_storage_result = - bpf_inode_storage_delete(&inode_storage_map, victim->d_inode); + err = bpf_inode_storage_delete(&inode_storage_map, victim->d_inode); + if (!err) + inode_storage_result = err; return 0; } @@ -82,19 +84,23 @@ int BPF_PROG(socket_bind, struct socket *sock, struct sockaddr *address, { __u32 pid = bpf_get_current_pid_tgid() >> 32; struct dummy_storage *storage; + int err; if (pid != monitored_pid) return 0; storage = bpf_sk_storage_get(&sk_storage_map, sock->sk, 0, - BPF_SK_STORAGE_GET_F_CREATE); + BPF_LOCAL_STORAGE_GET_F_CREATE); if (!storage) return 0; - if (storage->value == DUMMY_STORAGE_VALUE) + if (storage->value != DUMMY_STORAGE_VALUE) sk_storage_result = -1; - sk_storage_result = bpf_sk_storage_delete(&sk_storage_map, sock->sk); + err = bpf_sk_storage_delete(&sk_storage_map, sock->sk); + if (!err) + sk_storage_result = err; + return 0; } @@ -109,7 +115,7 @@ int BPF_PROG(socket_post_create, struct socket *sock, int family, int type, return 0; storage = bpf_sk_storage_get(&sk_storage_map, sock->sk, 0, - BPF_SK_STORAGE_GET_F_CREATE); + BPF_LOCAL_STORAGE_GET_F_CREATE); if (!storage) return 0; @@ -131,7 +137,7 @@ int BPF_PROG(file_open, struct file *file) return 0; storage = bpf_inode_storage_get(&inode_storage_map, file->f_inode, 0, - BPF_LOCAL_STORAGE_GET_F_CREATE); + BPF_LOCAL_STORAGE_GET_F_CREATE); if (!storage) return 0;