Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1115713rwn; Thu, 15 Sep 2022 10:39:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5UDAY/d0sin+mFiV2SuA5CL6fEZFIYsMH/9IPKtMaNmHBtImeCPckV/uznW3bKCk8daRfR X-Received: by 2002:a17:903:2d0:b0:172:b63b:3a1e with SMTP id s16-20020a17090302d000b00172b63b3a1emr681026plk.76.1663263549377; Thu, 15 Sep 2022 10:39:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663263549; cv=none; d=google.com; s=arc-20160816; b=nOjaKLovlNOC7BXl4nsjhV6JS3GwyIt7IFnTkwBkBUKnq2C6Ny1IAiXYq7exMdx3MF xmZoFQlVyCOVG5beoaUkmbTKjMcvfNDmWKnGwEuHYlZjDI5UzRzUXVr8Bks3bCRSeQOl WpmAih89aLo6IlnK5eI+fo8u7JfNI7DUcjor+SwX9A53LTK47IezLS9oJxEqbgM/jARR bxuHw2nW0ExQMTz6NWk5nDIOW5/JxeNZhOqEQDmYV4d25RT19zi6pVja+X9jFdpe9JNj usA4B9QhLDFf8hSlkc3e4fhi5AT+gnKGQ8mayBqXO0jCyShRwhN8iVXpO15AL9UwqoQR uHlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=n7clma79Elx90LhQdYIMW3bMpo15PALFqDOV8+Z9bcI=; b=jXmB+UK/0pL7kzWmf5YwX+lzqq9vSpbFfqGscCdMYNmSrrhziTu+vpMIUTqcHyHpxy PENkLJnbSiIRgoC8D1B1xG4ZyUF4JCVQ3RPy8wRguqIegNHJNnoCt85ThQZs9ZR66YRO 4Vodfshym3rRSIiCVB1phstYvNTKsRn7Uzmz3tReqTrdQeZ85wIO/cz/r9/WLf8rZvFj uUj1NvkCqeehr2EvuZlkTNFem6T6O2ldoC6ZWHE41j3/sVSMHtfM9MayBl6/wAaJ6+ZA cf52CCkyFvSoX92sSyLmc+LFhPlvvWafJlwXRV5RZXdrG+NPNkVWd816IBW5lxkszEjw eZZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XD60SOBg; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oe10-20020a17090b394a00b001fd87298f34si18394322pjb.54.2022.09.15.10.38.56; Thu, 15 Sep 2022 10:39:09 -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=@kernel.org header.s=k20201202 header.b=XD60SOBg; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229876AbiIOQMH (ORCPT + 99 others); Thu, 15 Sep 2022 12:12:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229824AbiIOQMF (ORCPT ); Thu, 15 Sep 2022 12:12:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DABB915D8 for ; Thu, 15 Sep 2022 09:12:04 -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 DE8866252D for ; Thu, 15 Sep 2022 16:12:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51AEBC4347C for ; Thu, 15 Sep 2022 16:12:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663258323; bh=biii+7n43gDq9XV3lLWEwCgiBUcjGdS9pCCJ+UVSt80=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=XD60SOBgjmqG2oE/hYFdoVR/0o9EqUozlXe2HtAuCRzaStarFf8z/YDdABs3Q1Utf 8jfXldXFUyy6syrxYUcjYHYL1mZXQsrS3GRRcCNsWeBwQ5jsVG3gX0iZBzWRo7whTy Slcc+9a3Y/Q5kRflAZB23mYWDRktGAiKJxRxVihqcJEyjjo6H2l9i/H5PCbec12NSt Er+zMu9vwqZAwy5AfnXQNEDcFtfzOovBS6tAehYkYNiBMi05FZv5RpUMykkRoMAS4B V1jvalmzh0SH9DwhfQyWUv2dqbg3YB8Wp6Iz0y476MmivxD2t9cDcDjgpOgQIPjFEH tbpNB1W2HLICA== Received: by mail-lf1-f44.google.com with SMTP id f14so30199711lfg.5 for ; Thu, 15 Sep 2022 09:12:03 -0700 (PDT) X-Gm-Message-State: ACrzQf0RuFhnhhxpLN23q9nESGw40lR1WC7mS/JwoNAkbFs66zcpKUMV f8zlAus6PapCp5Y68Ox0CaznN1lF1V5+QpBBMWVB6g== X-Received: by 2002:a17:906:9bd3:b0:778:c8e0:fcee with SMTP id de19-20020a1709069bd300b00778c8e0fceemr471268ejc.275.1663258310370; Thu, 15 Sep 2022 09:11:50 -0700 (PDT) MIME-Version: 1.0 References: <20220909120736.1027040-1-roberto.sassu@huaweicloud.com> <20220909120736.1027040-12-roberto.sassu@huaweicloud.com> In-Reply-To: <20220909120736.1027040-12-roberto.sassu@huaweicloud.com> From: KP Singh Date: Thu, 15 Sep 2022 17:11:39 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v17 11/12] selftests/bpf: Add test for bpf_verify_pkcs7_signature() kfunc To: Roberto Sassu Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, dhowells@redhat.com, jarkko@kernel.org, rostedt@goodmis.org, mingo@redhat.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, shuah@kernel.org, bpf@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, deso@posteo.net, memxor@gmail.com, Roberto Sassu , Joanne Koong Content-Type: text/plain; charset="UTF-8" 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 autolearn=unavailable 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 On Fri, Sep 9, 2022 at 1:10 PM Roberto Sassu wrote: > > From: Roberto Sassu > [...] > +} > diff --git a/tools/testing/selftests/bpf/progs/test_verify_pkcs7_sig.c b/tools/testing/selftests/bpf/progs/test_verify_pkcs7_sig.c > new file mode 100644 > index 000000000000..4ceab545d99a > --- /dev/null > +++ b/tools/testing/selftests/bpf/progs/test_verify_pkcs7_sig.c > @@ -0,0 +1,100 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +/* > + * Copyright (C) 2022 Huawei Technologies Duesseldorf GmbH > + * > + * Author: Roberto Sassu > + */ > + > +#include "vmlinux.h" > +#include > +#include > +#include > + > +#define MAX_DATA_SIZE (1024 * 1024) > +#define MAX_SIG_SIZE 1024 > + > +typedef __u8 u8; > +typedef __u16 u16; > +typedef __u32 u32; > +typedef __u64 u64; I think you can avoid this and just use u32 and u64 directly. > + > +struct bpf_dynptr { > + __u64 :64; > + __u64 :64; > +} __attribute__((aligned(8))); > + I think you are doing this because including the uapi headers causes type conflicts. This does happen quite often. What do other folks think about doing something like #define DYNPTR(x) ((void *)x) It seems like this will be an issue anytime we use the helpers with vmlinux.h and users will always have to define this type in their tests. - KP > +extern struct bpf_key *bpf_lookup_user_key(__u32 serial, __u64 flags) __ksym; > +extern struct bpf_key *bpf_lookup_system_key(__u64 id) __ksym; > +extern void bpf_key_put(struct bpf_key *key) __ksym; > +extern int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_ptr, > + struct bpf_dynptr *sig_ptr, > + struct bpf_key *trusted_keyring) __ksym; > + > +u32 monitored_pid; > +u32 user_keyring_serial; > +u64 system_keyring_id; > + > +struct data { > + u8 data[MAX_DATA_SIZE]; > + u32 data_len; > + u8 sig[MAX_SIG_SIZE]; > + u32 sig_len; > +}; > + > +struct { > + __uint(type, BPF_MAP_TYPE_ARRAY); > + __uint(max_entries, 1); > + __type(key, __u32); > + __type(value, struct data); > +} data_input SEC(".maps"); > + > +char _license[] SEC("license") = "GPL"; > + > +SEC("lsm.s/bpf") > +int BPF_PROG(bpf, int cmd, union bpf_attr *attr, unsigned int size) > +{ > + struct bpf_dynptr data_ptr, sig_ptr; > + struct data *data_val; > + struct bpf_key *trusted_keyring; > + u32 pid; > + u64 value; > + int ret, zero = 0; > + > + pid = bpf_get_current_pid_tgid() >> 32; > + if (pid != monitored_pid) > + return 0; > + > + data_val = bpf_map_lookup_elem(&data_input, &zero); > + if (!data_val) > + return 0; > + > + bpf_probe_read(&value, sizeof(value), &attr->value); > + > + bpf_copy_from_user(data_val, sizeof(struct data), > [...] > -- > 2.25.1 >