Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1473565rdb; Wed, 24 Jan 2024 17:26:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEyl4xP1MUDEZOUEd41PtMwu7U2dfVCTkUmhXgZys4/+e7oDTyMgUFBcxC3uC9nvxiiPg6c X-Received: by 2002:a05:6a00:4fd2:b0:6db:d65d:39ae with SMTP id le18-20020a056a004fd200b006dbd65d39aemr540664pfb.29.1706146002877; Wed, 24 Jan 2024 17:26:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706146002; cv=pass; d=google.com; s=arc-20160816; b=jtttslc9wmJlwVBDq5FNi74s2shXKPK5Y3ZuGW8cD5i2jroeK8WfRQUZXT+/MyL3gT 5imXkOLwtRHHn/cazQI2gWHBo7VW2Ly1/kdGcJW9WE8SfIKng5MJSBh/JuRpIy9QeIUP qRFZdLyKFF0PYM4SXMJuPBLpB2uhooCyXcaBsdu3IcCx1j6ausD2S55+/WCxsMQ+wl/f GeEqs392iziJZlAiFBWtprcXnIatzCGKHOXcbvd9yg6atHwohV7B0inSHdJMof+a+a6J ql2SQ/tQC5APS6MY71C32Qfed5ikM9H3fhy5f+yqtK9uPSwDRDEZk0jwCBJ14u70VJrX YwHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=ALoEZM9RVE/tOlWK9AF2LXEypS3Bld3Rxux5elBLvf8=; fh=N/qKNhXGRf18UdRS1T/VMp1656TBZaArriSM2jCbLk0=; b=rZFci6eMNHUxsXnjrPThJeJ/AYpZ+D1c/Kt4GHbu+l+lNnVwBWoCCPi4TfHJcCRXY3 quL9xVwxk8sDEWPeHv+pp/MEjE96Vu/hcCIvQac450tDeDQLqUhfIS6Hj0Ea9CC0Nl8I svZgBSOujEz1ba+MrumFxou9OL6PWqFjE8QDLlcXTbaf+mWJk6VtzSME84MoHAvxOzUM S9MX2Hkx71CAXudFmE+O8Q9C5ROVnCHYQsfB+bFBZRaiTC7oO9hKTcSHPP3KA0OgVo7d FiUHVzXcFWFLIaUZ63tyPoSvNwECSXgzbjuqfZgV6N1XI6dMgG3XRyBEE7MTo6iwXPQO 4A6g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Yzh7DPss; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-crypto+bounces-1596-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1596-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m62-20020a625841000000b006d9b327f2d8si14442006pfb.74.2024.01.24.17.26.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 17:26:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-1596-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Yzh7DPss; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-crypto+bounces-1596-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1596-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 75AD7287563 for ; Thu, 25 Jan 2024 01:26:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3F7810E6; Thu, 25 Jan 2024 01:26:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Yzh7DPss" X-Original-To: linux-crypto@vger.kernel.org Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE80B6FA7 for ; Thu, 25 Jan 2024 01:26:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706145995; cv=none; b=RT+0eU0dyWeB6/POBeerMDENVMeTxsNmCjRn58Ey7naawbGhayAn7K70MHlfwa2HdlKojm3T2JtzOQv+YmI13UWdFFTfgVGO5Z7JQaAoKaxBhp7TYirltlLfYq0RW9CFkhh/NclcA+0ncdctiTksiKtF3tg3xUPAEYduu2cDtUI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706145995; c=relaxed/simple; bh=/bG04frI+8AEtX1UkmXUckcVaY83ebVSVcY77KIMgF0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Jx9Ye8sL6u+2BOpzoai5Kjf4lANdAB0BqS51Ls8ax+1uILdfV0Eg8Ij01s0dpCemlRGD+eGHQh+KbIEU+sFUhZZ6wXQJj+uRwQoFzwgb/KVr9lvUw0EtJPI57dCoIgLKqv0ZtpRvyLp6Nu7PeiCJ4Dbdw5bNh0wx9IbRM1B9DFA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Yzh7DPss; arc=none smtp.client-ip=91.218.175.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1706145991; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ALoEZM9RVE/tOlWK9AF2LXEypS3Bld3Rxux5elBLvf8=; b=Yzh7DPss9iVKI7RV511dKJG2UWex+qR0YNUkFdNKTW6lvW9w+8xGoCD3U7bRfq+3aklkgl VQRDF4Hl/dgEekNxkIbCM5CM41FImyn14RD/mHrrcFOgsESJ58Wa+KJYjNY7rzAvOTtQXX SIIPQT1meee/i7A/TlSCgOqebv7N63g= Date: Wed, 24 Jan 2024 17:26:24 -0800 Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v8 3/3] selftests: bpf: crypto skcipher algo selftests Content-Language: en-US To: Vadim Fedorenko Cc: netdev@vger.kernel.org, linux-crypto@vger.kernel.org, bpf@vger.kernel.org, Victor Stewart , Vadim Fedorenko , Jakub Kicinski , Andrii Nakryiko , Alexei Starovoitov , Mykola Lysenko , Herbert Xu References: <20240115220803.1973440-1-vadfed@meta.com> <20240115220803.1973440-3-vadfed@meta.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: <20240115220803.1973440-3-vadfed@meta.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 1/15/24 2:08 PM, Vadim Fedorenko wrote: > +static void deinit_afalg(void) > +{ > + if (tfmfd) The test should be (tfmfd != -1) ? > + close(tfmfd); > + if (opfd) Same here. > + close(opfd); > +} [ ... ] > +SEC("?fentry.s/bpf_fentry_test1") > +__failure __msg("Unreleased reference") The error message is not checked. Take a look at how other tests use RUN_TESTS. > +int BPF_PROG(crypto_acquire) > +{ > + struct bpf_crypto_ctx *cctx; > + struct bpf_dynptr key = {}; > + int err = 0; > + > + status = 0; > + > + bpf_dynptr_from_mem(crypto_key, sizeof(crypto_key), 0, &key); > + cctx = bpf_crypto_ctx_create("skcipher", "ecb(aes)", &key, 0, &err); > + > + if (!cctx) { > + status = err; > + return 0; > + } > + > + cctx = bpf_crypto_ctx_acquire(cctx); > + if (!cctx) > + return -EINVAL; > + > + bpf_crypto_ctx_release(cctx); > + > + return 0; > +} > + > +SEC("tc") > +int decrypt_sanity(struct __sk_buff *skb) > +{ > + struct __crypto_ctx_value *v; > + struct bpf_crypto_ctx *ctx; > + struct bpf_dynptr psrc, pdst, iv; > + int err; > + > + err = skb_dynptr_validate(skb, &psrc); > + if (err < 0) { > + status = err; > + return TC_ACT_SHOT; > + } > + > + v = crypto_ctx_value_lookup(); > + if (!v) { > + status = -ENOENT; > + return TC_ACT_SHOT; > + } > + > + ctx = v->ctx; > + if (!ctx) { > + status = -ENOENT; > + return TC_ACT_SHOT; > + } > + > + bpf_dynptr_from_mem(dst, sizeof(dst), 0, &pdst); > + /* iv dynptr has to be initialized with 0 size, but proper memory region > + * has to be provided anyway > + */ > + bpf_dynptr_from_mem(dst, 0, 0, &iv); It would be nice to allow passing NULL as an optional "iv" arg. It could be a future improvement. Overall lgtm. Please add a cover letter in v4 and also the benchmark test that was brought up a while back. > + > + status = bpf_crypto_decrypt(ctx, &psrc, &pdst, &iv); > + > + return TC_ACT_SHOT; > +} > + > +SEC("tc") > +int encrypt_sanity(struct __sk_buff *skb) > +{ > + struct __crypto_ctx_value *v; > + struct bpf_crypto_ctx *ctx; > + struct bpf_dynptr psrc, pdst, iv; > + int err; > + > + status = 0; > + > + err = skb_dynptr_validate(skb, &psrc); > + if (err < 0) { > + status = err; > + return TC_ACT_SHOT; > + } > + > + v = crypto_ctx_value_lookup(); > + if (!v) { > + status = -ENOENT; > + return TC_ACT_SHOT; > + } > + > + ctx = v->ctx; > + if (!ctx) { > + status = -ENOENT; > + return TC_ACT_SHOT; > + } > + > + bpf_dynptr_from_mem(dst, sizeof(dst), 0, &pdst); > + /* iv dynptr has to be initialized with 0 size, but proper memory region > + * has to be provided anyway > + */ > + bpf_dynptr_from_mem(dst, 0, 0, &iv); > + > + status = bpf_crypto_encrypt(ctx, &psrc, &pdst, &iv); > + > + return TC_ACT_SHOT; > +} > + > +char __license[] SEC("license") = "GPL";