lib/bpf_legacy: Use userspace SHA-1 code instead of AF_ALG
Subsystems (5)
PATCH v2 1/1 lib/bpf_legacy: Use userspace SHA-1 code instead of AF_ALG
Add a basic SHA-1 implementation to lib/, and make lib/bpf_legacy.c use it to calculate SHA-1 digests instead of the previous AF_ALG-based code.
This eliminates the dependency on AF_ALG, specifically the kernel config options CONFIG_CRYPTO_USER_API_HASH and CONFIG_CRYPTO_SHA1.
Over the years AF_ALG has been very problematic, and it is also not supported on all kernels. Escalating to the kernel's privileged execution context merely to calculate software algorithms, which can be done in userspace instead, is not something that should have ever been supported. Even on kernels that support it, the syscall overhead of AF_ALG means that it is often slower than userspace code.
Let's do the right thing here, and allow people to disable AF_ALG support (or not enable it) on systems where iproute2 is the only user.
---
Changed in v2:
- Corrected error handling for when bpf_obj_hash() fails
- Added more detail to commit message
include/bpf_util.h | 5 -- include/sha1.h | 18 ++++++ include/uapi/linux/if_alg.h | 61 -------------------- lib/Makefile | 2 +- lib/bpf_legacy.c | 109 +++++++++--------------------------- lib/sha1.c | 108 +++++++++++++++++++++++++++++++++++ 6 files changed, 154 insertions(+), 149 deletions(-) create mode 100644 include/sha1.h delete mode 100644 include/uapi/linux/if_alg.h create mode 100644 lib/sha1.c
include/bpf_util.h +0 -5
@@ -12,11 +12,10 @@#include <linux/bpf.h> #include <linux/btf.h> #include <linux/filter.h> #include <linux/magic.h> #include <linux/elf-em.h> -#include <linux/if_alg.h> #include "utils.h" #include "bpf_scm.h" #define BPF_ENV_UDS "TC_BPF_UDS"
@@ -38,14 +37,10 @@# define TRACEFS_MAGIC 0x74726163#endif #define TRACE_DIR_MNT "/sys/kernel/tracing" -#ifndef AF_ALG -# define AF_ALG 38 -#endif -#ifndef EM_BPF # define EM_BPF 247#endif struct bpf_cfg_ops {
include/sha1.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* SHA-1 message digest algorithm +* +* Copyright 2025 Google LLC +*/ +#ifndef __SHA1_H__ +#define __SHA1_H__ + +#include <linux/types.h> +#include <stddef.h> + +#define SHA1_DIGEST_SIZE 20 +#define SHA1_BLOCK_SIZE 64 + +void sha1 (const __u8 *data,size_t len,__u8 out[SHA1_DIGEST_SIZE ]); + +#endif /* __SHA1_H__ */
include/uapi/linux/if_alg.h deleted +0 -61
61 lines not on this page · raw message
lib/Makefile +1 -1
@@ -4,11 +4,11 @@ include ../config.mk CFLAGS += -fPIC UTILOBJ = utils.o utils_math.o rt_names.o ll_map.o ll_types.o ll_proto.o ll_addr.o \ inet_proto.o namespace.o json_writer.o json_print.o json_print_math.o \ names.o color.o bpf_legacy.o bpf_glue.o exec.o fs.o cg_map.o \ - ppp_proto.o bridge.o + ppp_proto.o bridge.o sha1.o ifeq ($(HAVE_ELF),y) ifeq ($(HAVE_LIBBPF),y) UTILOBJ += bpf_libbpf.o endif
lib/bpf_legacy.c +27 -82
199 lines not on this page · raw message
lib/sha1.c new file +108 -0
108 lines not on this page · raw message
base-commit: 1f7924938884235daa5594f1d0f18c5b07fa9d74
Signature · 1 line
2.51.0
Quoted 7 lines · Eric Biggers
Add a basic SHA-1 implementation to
lib/, and makelib/bpf_legacy.cuse it to calculate SHA-1 digests instead of the previous AF_ALG-based code.This eliminates the dependency on
AF_ALG, specifically the kernel config optionsCONFIG_CRYPTO_USER_API_HASHandCONFIG_CRYPTO_SHA1.
Quoted 6 lines
Over the years
AF_ALGhas been very problematic, and it is also not supported on all kernels. Escalating to the kernel's privileged execution context merely to calculate software algorithms, which can be done in userspace instead, is not something that should have ever been supported. Even on kernels that support it, the syscall overhead ofAF_ALGmeans that it is often slower than userspace code.
Help me understand the crusade against AF_ALG.
Do you want to deprecate AF_ALG altogether or when it's used for sha-s like sha1 and sha256 ?
I thought the main advantage of going through the kernel is that the kernel might have an optimized implementation for a specific architecture, while the open coded C version is generic. The cost of syscall and copies in/out is small compared to actual math, especially since compilers might not be smart enough to use single asm insn for rol32() C function.
sha1/256 are simple enough in plain C, but other crypto/hash could be complex and the kernel may have HW acceleration for them. CONFIG_CRYPTO_USER_API_HASH has been there forever and plenty of projects have code to use that. Like qemu, stress-ng, ruby. python and rust have standard binding for af_alg too.
If the kernel has optimized and/or hw accelerated crypto, I see an appeal to alway use AF_ALG when it's available.
Quoted 15 lines · Alexei Starovoitov
Quoted 7 lines · Eric Biggers
Add a basic SHA-1 implementation to
lib/, and makelib/bpf_legacy.cuse it to calculate SHA-1 digests instead of the previous AF_ALG-based code.This eliminates the dependency on
AF_ALG, specifically the kernel config optionsCONFIG_CRYPTO_USER_API_HASHandCONFIG_CRYPTO_SHA1.Quoted 6 lines
Over the years
AF_ALGhas been very problematic, and it is also not supported on all kernels. Escalating to the kernel's privileged execution context merely to calculate software algorithms, which can be done in userspace instead, is not something that should have ever been supported. Even on kernels that support it, the syscall overhead ofAF_ALGmeans that it is often slower than userspace code.
Quoted 3 lines
Help me understand the crusade against
AF_ALG.
Do you want to deprecateAF_ALGaltogether or when it's used for sha-s like sha1 and sha256 ?
Altogether, when possible. AF_ALG has been (and continues to be) incredibly problematic, for both security and maintainability.
Quoted 6 lines
I thought the main advantage of going through the kernel is that the kernel might have an optimized implementation for a specific architecture, while the open coded C version is generic. The cost of syscall and copies in/out is small compared to actual math, especially since compilers might not be smart enough to use single asm insn for
rol32()C function.
Not for small amounts of data, since syscalls are expensive these days.
(Aren't BPF programs usually fairly small?)
BTW, both gcc and clang reliably lower rol32() to a single instruction.
Quoted 7 lines
sha1/256 are simple enough in plain C, but other
crypto/hashcould be complex and the kernel may have HW acceleration for them.CONFIG_CRYPTO_USER_API_HASHhas been there forever and plenty of projects have code to use that. Like qemu, stress-ng, ruby. python and rust have standard binding foraf_algtoo.
If the kernel has optimized and/or hw accelerated crypto, I see an appeal to alway useAF_ALGwhen it's available.
Well, userspace programs that want accelerated crypto routines without incorporating them themselves should just use a userspace library that has them. It's not hard.
But iproute2 should be fine with just the generic C code.
As for why AF_ALG support keeps showing up in different programs, it's mainly just a misunderstanding. But I think you're also overestimating how often it's used. Your 5 examples were 4 bindings (not users), and 1 user where it's disabled by default.
There are Linux systems where it's only iproute2 that's blocking CONFIG_CRYPTO_USER_API_HASH from being disabled. This patch is really valuable on such systems.
- Eric
Quoted 17 lines · Eric Biggers
Quoted 15 lines · Alexei Starovoitov
Quoted 13 lines · Eric Biggers
Add a basic SHA-1 implementation to
lib/, and makelib/bpf_legacy.cuse it to calculate SHA-1 digests instead of the previous AF_ALG-based code.This eliminates the dependency on
AF_ALG, specifically the kernel config optionsCONFIG_CRYPTO_USER_API_HASHandCONFIG_CRYPTO_SHA1.Over the years
AF_ALGhas been very problematic, and it is also not supported on all kernels. Escalating to the kernel's privileged execution context merely to calculate software algorithms, which can be done in userspace instead, is not something that should have ever been supported. Even on kernels that support it, the syscall overhead ofAF_ALGmeans that it is often slower than userspace code.
Quoted 6 lines
Quoted 3 lines
Help me understand the crusade against
AF_ALG.
Do you want to deprecateAF_ALGaltogether or when it's used for sha-s like sha1 and sha256 ?Altogether, when possible.
AF_ALGhas been (and continues to be) incredibly problematic, for both security and maintainability.
Could you provide an example of a security issue with AF_ALG ? Not challenging the statement. Mainly curious what is going to understand it better and pass the message.
Quoted 10 lines
Quoted 6 lines
I thought the main advantage of going through the kernel is that the kernel might have an optimized implementation for a specific architecture, while the open coded C version is generic. The cost of syscall and copies in/out is small compared to actual math, especially since compilers might not be smart enough to use single asm insn for
rol32()C function.Not for small amounts of data, since syscalls are expensive these days.
(Aren't BPF programs usually fairly small?)
Depends on the definition of small :)
The largest we have in production is 620kbytes of ELF. Couple dozens between 100k to 400k.
And a hundred between 5k to 50k.
Quoted 17 lines
BTW, both gcc and clang reliably lower
rol32()to a single instruction.Quoted 7 lines
sha1/256 are simple enough in plain C, but other
crypto/hashcould be complex and the kernel may have HW acceleration for them.CONFIG_CRYPTO_USER_API_HASHhas been there forever and plenty of projects have code to use that. Like qemu, stress-ng, ruby. python and rust have standard binding foraf_algtoo.
If the kernel has optimized and/or hw accelerated crypto, I see an appeal to alway useAF_ALGwhen it's available.Well, userspace programs that want accelerated crypto routines without incorporating them themselves should just use a userspace library that has them. It's not hard.
But iproute2 should be fine with just the generic C code.
Quoted 8 lines
As for why
AF_ALGsupport keeps showing up in different programs, it's mainly just a misunderstanding. But I think you're also overestimating how often it's used. Your 5 examples were 4 bindings (not users), and 1 user where it's disabled by default.There are Linux systems where it's only iproute2 that's blocking
CONFIG_CRYPTO_USER_API_HASHfrom being disabled. This patch is really valuable on such systems.
Fair enough.
Quoted 22 lines · Alexei Starovoitov
Quoted 21 lines · Eric Biggers
Quoted 18 lines · Alexei Starovoitov
Quoted 7 lines · Eric Biggers
Add a basic SHA-1 implementation to
lib/, and makelib/bpf_legacy.cuse it to calculate SHA-1 digests instead of the previous AF_ALG-based code.This eliminates the dependency on
AF_ALG, specifically the kernel config optionsCONFIG_CRYPTO_USER_API_HASHandCONFIG_CRYPTO_SHA1.Quoted 6 lines
Over the years
AF_ALGhas been very problematic, and it is also not supported on all kernels. Escalating to the kernel's privileged execution context merely to calculate software algorithms, which can be done in userspace instead, is not something that should have ever been supported. Even on kernels that support it, the syscall overhead ofAF_ALGmeans that it is often slower than userspace code.Help me understand the crusade against
AF_ALG.
Do you want to deprecateAF_ALGaltogether or when it's used for sha-s like sha1 and sha256 ?
Quoted 6 lines
Quoted 2 lines
Altogether, when possible.
AF_ALGhas been (and continues to be) incredibly problematic, for both security and maintainability.Could you provide an example of a security issue with
AF_ALG? Not challenging the statement. Mainly curious what is going to understand it better and pass the message.
It's a gold mine for attackers looking to exploit the kernel. Here are some examples from the CVE list when searching for "AF_ALG":
https://nvd.nist.gov/vuln/detail/CVE-2025-38079
In the Linux kernel, the following vulnerability has been resolved:
crypto: algif_hash - fix double free in hash_accept If accept(2) is called on socket type algif_hash with MSG_MORE flag set and crypto_ahash_import fails, sk2 is freed. However, it is also freed in af_alg_release, leading to slab-use-after-free error.
https://nvd.nist.gov/vuln/detail/CVE-2025-37808
In the Linux kernel, the following vulnerability has been resolved:
crypto: null - Use spin lock instead of mutex As the null algorithm may be freed in softirq context through af_alg, use spin locks instead of mutexes to protect the default null algorithm.
https://nvd.nist.gov/vuln/detail/CVE-2024-26824
In the Linux kernel, the following vulnerability has been resolved:
crypto: algif_hash - Remove bogus SGL free on zero-length error path When a zero-length message is hashed by algif_hash, and an error is triggered, it tries to free an SG list that was never allocated in the first place. Fix this by not freeing the SG list on the zero-length error path.
https://nvd.nist.gov/vuln/detail/CVE-2022-48781
In the Linux kernel, the following vulnerability has been resolved:
crypto: af_alg - get rid of alg_memory_allocated alg_memory_allocated does not seem to be really used. alg_proto does have a .memory_allocated field, but no corresponding .sysctl_mem. This means sk_has_account() returns true, but all sk_prot_mem_limits() users will trigger a NULL dereference
https://nvd.nist.gov/vuln/detail/CVE-2019-8912
n the Linux kernel through 4.20.11, af_alg_release() in crypto/af_alg.c neglects to set a NULL value for a certain structure member, which leads to a use-after-free in sockfs_setattr.
https://nvd.nist.gov/vuln/detail/CVE-2018-14619
A flaw was found in the crypto subsystem of the Linux kernel before version kernel-4.15-rc4. The "null skcipher" was being dropped when each af_alg_ctx was freed instead of when the aead_tfm was freed. This can cause the null skcipher to be freed while it is still in use leading to a local user being able to crash the system or possibly escalate privileges.
https://nvd.nist.gov/vuln/detail/CVE-2017-18075
crypto/pcrypt.c in the Linux kernel before 4.14.13 mishandles freeing instances, allowing a local user able to access the AF_ALG-based AEAD interface (CONFIG_CRYPTO_USER_API_AEAD) and pcrypt (CONFIG_CRYPTO_PCRYPT) to cause a denial of service (kfree of an incorrect pointer) or possibly have unspecified other impact by executing a crafted sequence of system calls.
https://nvd.nist.gov/vuln/detail/CVE-2017-17806
The HMAC implementation (crypto/hmac.c) in the Linux kernel before 4.14.8 does not validate that the underlying cryptographic hash algorithm is unkeyed, allowing a local attacker able to use the AF_ALG-based hash interface (CONFIG_CRYPTO_USER_API_HASH) and the SHA-3 hash algorithm (CONFIG_CRYPTO_SHA3) to cause a kernel stack buffer overflow by executing a crafted sequence of system calls that encounter a missing SHA-3 initialization.
https://nvd.nist.gov/vuln/detail/CVE-2017-17805
The Salsa20 encryption algorithm in the Linux kernel before 4.14.8 does not correctly handle zero-length inputs, allowing a local attacker able to use the AF_ALG-based skcipher interface (CONFIG_CRYPTO_USER_API_SKCIPHER) to cause a denial of service (uninitialized-memory free and kernel crash) or have unspecified other impact by executing a crafted sequence of system calls that use the blkcipher_walk API. Both the generic implementation (crypto/salsa20_generic.c) and x86 implementation (arch/x86/crypto/salsa20_glue.c) of Salsa20 were vulnerable.
https://nvd.nist.gov/vuln/detail/CVE-2016-10147
crypto/mcryptd.c in the Linux kernel before 4.8.15 allows local users to cause a denial of service (NULL pointer dereference and system crash) by using an AF_ALG socket with an incompatible algorithm, as demonstrated by mcryptd(md5).
https://nvd.nist.gov/vuln/detail/CVE-2015-8970
crypto/algif_skcipher.c in the Linux kernel before 4.4.2 does not verify that a setkey operation has been performed on an AF_ALG socket before an accept system call is processed, which allows local users to cause a denial of service (NULL pointer dereference and system crash) via a crafted application that does not supply a key, related to the lrw_crypt function in crypto/lrw.c.
https://nvd.nist.gov/vuln/detail/CVE-2015-3331
The __driver_rfc4106_decrypt function in arch/x86/crypto/aesni-intel_glue.c in the Linux kernel before 3.19.3 does not properly determine the memory locations used for encrypted data, which allows context-dependent attackers to cause a denial of service (buffer overflow and system crash) or possibly execute arbitrary code by triggering a crypto API call, as demonstrated by use of a libkcapi test program with an AF_ALG(aead) socket.
https://nvd.nist.gov/vuln/detail/CVE-2014-9644
The Crypto API in the Linux kernel before 3.18.5 allows local users to load arbitrary kernel modules via a bind system call for an AF_ALG socket with a parenthesized module template expression in the salg_name field, as demonstrated by the vfat(aes) expression, a different vulnerability than CVE-2013-7421.
https://nvd.nist.gov/vuln/detail/CVE-2013-7421
The Crypto API in the Linux kernel before 3.18.5 allows local users to load arbitrary kernel modules via a bind system call for an AF_ALG socket with a module name in the salg_name field, a different vulnerability than CVE-2014-9644.
https://nvd.nist.gov/vuln/detail/CVE-2011-4081
crypto/ghash-generic.c in the Linux kernel before 3.1 allows local users to cause a denial of service (NULL pointer dereference and OOPS) or possibly have unspecified other impact by triggering a failed or missing ghash_setkey function call, followed by a (1) ghash_update function call or (2) ghash_final function call, as demonstrated by a write operation on an AF_ALG socket.
- Eric
Alexei Starovoitov
Acked-byQuoted 27 lines · Eric Biggers
Quoted 25 lines · Alexei Starovoitov
Quoted 23 lines · Eric Biggers
Quoted 15 lines · Alexei Starovoitov
Quoted 7 lines · Eric Biggers
Add a basic SHA-1 implementation to
lib/, and makelib/bpf_legacy.cuse it to calculate SHA-1 digests instead of the previous AF_ALG-based code.This eliminates the dependency on
AF_ALG, specifically the kernel config optionsCONFIG_CRYPTO_USER_API_HASHandCONFIG_CRYPTO_SHA1.Quoted 6 lines
Over the years
AF_ALGhas been very problematic, and it is also not supported on all kernels. Escalating to the kernel's privileged execution context merely to calculate software algorithms, which can be done in userspace instead, is not something that should have ever been supported. Even on kernels that support it, the syscall overhead ofAF_ALGmeans that it is often slower than userspace code.Quoted 3 lines
Help me understand the crusade against
AF_ALG.
Do you want to deprecateAF_ALGaltogether or when it's used for sha-s like sha1 and sha256 ?Altogether, when possible.
AF_ALGhas been (and continues to be) incredibly problematic, for both security and maintainability.
Quoted 6 lines
Quoted 3 lines
Could you provide an example of a security issue with
AF_ALG? Not challenging the statement. Mainly curious what is going to understand it better and pass the message.It's a gold mine for attackers looking to exploit the kernel. Here are some examples from the CVE list when searching for "
AF_ALG":
Ohh. I see. That made it very concrete. Thanks!
[Adding David Ahern. I overlooked that iproute2 has separate maintainers for the main tree and the next tree.]
Quoted 13 lines · Eric Biggers
Add a basic SHA-1 implementation to
lib/, and makelib/bpf_legacy.cuse it to calculate SHA-1 digests instead of the previous AF_ALG-based code.This eliminates the dependency on
AF_ALG, specifically the kernel config optionsCONFIG_CRYPTO_USER_API_HASHandCONFIG_CRYPTO_SHA1.Over the years
AF_ALGhas been very problematic, and it is also not supported on all kernels. Escalating to the kernel's privileged execution context merely to calculate software algorithms, which can be done in userspace instead, is not something that should have ever been supported. Even on kernels that support it, the syscall overhead ofAF_ALGmeans that it is often slower than userspace code.
Quoted 5 lines
Let's do the right thing here, and allow people to disable
AF_ALGsupport (or not enable it) on systems where iproute2 is the only user.Acked-by Ard Biesheuvel <[email protected]>Signed-off-by Eric Biggers <[email protected]>
Stephen and David, any interest in applying this patch?
- Eric
Quoted 20 lines · Eric Biggers
[Adding David Ahern. I overlooked that iproute2 has separate maintainers for the main tree and the next tree.]
Quoted 16 lines · Eric Biggers
Add a basic SHA-1 implementation to
lib/, and makelib/bpf_legacy.cuse it to calculate SHA-1 digests instead of the previous AF_ALG-based code.This eliminates the dependency on
AF_ALG, specifically the kernel config optionsCONFIG_CRYPTO_USER_API_HASHandCONFIG_CRYPTO_SHA1.Over the years
AF_ALGhas been very problematic, and it is also not supported on all kernels. Escalating to the kernel's privileged execution context merely to calculate software algorithms, which can be done in userspace instead, is not something that should have ever been supported. Even on kernels that support it, the syscall overhead ofAF_ALGmeans that it is often slower than userspace code.Let's do the right thing here, and allow people to disable
AF_ALGsupport (or not enable it) on systems where iproute2 is the only user.
Quoted 6 lines
Quoted 2 lines
Acked-by Ard Biesheuvel <[email protected]>Signed-off-by Eric Biggers <[email protected]>Stephen and David, any interest in applying this patch?
- Eric
I do not have a strong opinion in either direction.
If we are going to entertain removing AF_ALG code, we should apply the patch to iproute2-next at the beginning of a dev cycle to give maximum time for testing before it rolls out.
Quoted 26 lines · David Ahern
Quoted 25 lines · Eric Biggers
[Adding David Ahern. I overlooked that iproute2 has separate maintainers for the main tree and the next tree.]
Quoted 13 lines · Eric Biggers
Add a basic SHA-1 implementation to
lib/, and makelib/bpf_legacy.cuse it to calculate SHA-1 digests instead of the previous AF_ALG-based code.This eliminates the dependency on
AF_ALG, specifically the kernel config optionsCONFIG_CRYPTO_USER_API_HASHandCONFIG_CRYPTO_SHA1.Over the years
AF_ALGhas been very problematic, and it is also not supported on all kernels. Escalating to the kernel's privileged execution context merely to calculate software algorithms, which can be done in userspace instead, is not something that should have ever been supported. Even on kernels that support it, the syscall overhead ofAF_ALGmeans that it is often slower than userspace code.Quoted 5 lines
Let's do the right thing here, and allow people to disable
AF_ALGsupport (or not enable it) on systems where iproute2 is the only user.Acked-by Ard Biesheuvel <[email protected]>Signed-off-by Eric Biggers <[email protected]>Stephen and David, any interest in applying this patch?
Quoted 7 lines
Quoted 1 line
- Eric
I do not have a strong opinion in either direction.
If we are going to entertain removing
AF_ALGcode, we should apply the patch to iproute2-next at the beginning of a dev cycle to give maximum time for testing before it rolls out.
Any insight into when that would be?
- Eric
Quoted 6 lines · Eric Biggers
Quoted 3 lines
If we are going to entertain removing
AF_ALGcode, we should apply the patch to iproute2-next at the beginning of a dev cycle to give maximum time for testing before it rolls out.Any insight into when that would be?
re-send it now.
lib/sha1.c line 6
Quoted 12 lines · On Mon, 29 Sep 2025 12:46:48 -0700 Eric Biggers <[email protected]> wrote:
lib/sha1.c new file +6
-0@@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* SHA-1 message digest algorithm +* +* Copyright 2025 Google LLC +*/
Not a big fan of having actual crypto in iproute2. It creates even more technical debt.
Is there another crypto library that could be used?
Better yet, is there a reason legacy BPF code needs to still exist in current iproute2? When was the cut over.
Quoted 19 lines · Stephen Hemminger
lib/sha1.c line 6
Quoted 12 lines · On Mon, 29 Sep 2025 12:46:48 -0700 Eric Biggers <[email protected]> wrote:
lib/sha1.c new file +6
-0@@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* SHA-1 message digest algorithm +* +* Copyright 2025 Google LLC +*/ Not a big fan of having actual crypto in iproute2. It creates even more technical debt.
Is there another crypto library that could be used?
Currently iproute2 doesn't depend on OpenSSL. You can make it do that, if you want, and then you could use SHA-1 from there. I suspect that doing that would be much more trouble than just adding this SHA-1 code.
If you happen to be planning to pull in OpenSSL as a dependency for other reasons, it might make sense then.
Quoted 2 lines
Better yet, is there a reason legacy BPF code needs to still exist in current iproute2? When was the cut over.
No idea. That's a question for the BPF folks.
- Eric
Quoted 4 lines · Stephen Hemminger
On Mon, 29 Sep 2025 12:46:48 -0700
Eric Biggers <[email protected]> wrote:
Quoted 15 lines
lib/sha1.c line 6
Quoted 12 lines
lib/sha1.c new file +6
-0@@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* SHA-1 message digest algorithm +* +* Copyright 2025 Google LLC +*/ Not a big fan of having actual crypto in iproute2. It creates even more technical debt.
I understand your position, and I agree with it in principle.
However, the usual motivation for not re-inventing/re-implementing your own crypto is the risk associated with getting it wrong, or with failing to keep up with bug fixes etc. Given that SHA-1 is already considered broken beyond repair for its original purpose, and is now merely a glorified checksumming algorithm that is only kept around to retain backward compatibility, I'd argue that the situation is a bit different here.
Also, I strongly agree with Eric that a syscall interface to perform crypto s/w arithmetic that could easily execute in user space is something that should have never been added, and creates portability concerns for no good reason.
Hi,
Quoted 4 lines · Ard Biesheuvel
Also, I strongly agree with Eric that a syscall interface to perform crypto s/w arithmetic that could easily execute in user space is something that should have never been added, and creates portability concerns for no good reason.
Would it make sense to add crypto (and other transform) operations to the vdso, and make the decision whether the syscall is beneficial from there, depending on request/batch size (speed vs overhead tradeoff), data source/sink and available hardware?
For example, "gzip -d" pulling data from a file and writing to a file will need to transfer the data to userspace first, process it there, then transfer it back to kernelspace so it can be written to a file.
That's a lot of syscall and transfer overhead compared to just a single "decompress this file" call that keeps the data entirely in kernelspace -- so we benefit already even if there is no hardware gzip decompressor, and users that have one (such as myself) would benefit even further.
Simon
Quoted 10 lines · Simon Richter
Hi,
Quoted 4 lines · Ard Biesheuvel
Also, I strongly agree with Eric that a syscall interface to perform crypto s/w arithmetic that could easily execute in user space is something that should have never been added, and creates portability concerns for no good reason.
Quoted 5 lines
Would it make sense to add crypto (and other transform) operations to the vdso, and make the decision whether the syscall is beneficial from there, depending on request/batch size (speed vs overhead tradeoff), data source/sink and available hardware?
No. User space has all the tools it needs to make his determination itself, and OpenSSL (for example) already supports the 'afalg' engine, which will use AF_ALG, but transparently fall back to software crypto if the engine does not support the algorithm in question. So there is prior art, and therefore no need to complicate the kernel for this.
Note that taking the SHA-1 of a BPF program is guaranteed to be way below the threshold of being worth the overhead of using a crypto offload engine, so in the context of this thread, it is kind of a moot point.
Quoted 4 lines
For example, "gzip -d" pulling data from a file and writing to a file will need to transfer the data to userspace first, process it there, then transfer it back to kernelspace so it can be written to a file.
That is a different matter, and AF_ALG does not really help here at all. The crypto equivalent of what you describe already exists in fscrypt, which can transparently encrypt files, making use of whichever flavor of crypto is available, including inline crypto, where the h/w accelerator is in the storage controller, and not in a separate IP block. I'm not a file system expert, but AFAIK, some file systems already support compression at the file level as well, in which case h/w offload will be used where available, and the compressed data never travels to user space.
Similarly, on the networking side, there are things like VPN acceleration and kTLS, where the crypto offload is combined with the networking hardware.
Discrete crypto offload hardware is simply not something that has a lot of good use cases anymore.