]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
xdrgen: Add enum value validation to generated decoders
authorChuck Lever <chuck.lever@oracle.com>
Fri, 26 Dec 2025 15:19:35 +0000 (10:19 -0500)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 26 Jan 2026 15:10:58 +0000 (10:10 -0500)
commit5288993c4d1a8e59310e007aa68cf9b856551cc6
tree79b7db9138895d7c48bee96fd7c338264b0b2694
parent4c53b89032f14577e94d747a3ca0aee63f18d856
xdrgen: Add enum value validation to generated decoders

XDR enum decoders generated by xdrgen do not verify that incoming
values are valid members of the enum. Incoming out-of-range values
from malicious or buggy peers propagate through the system
unchecked.

Add validation logic to generated enum decoders using a switch
statement that explicitly lists valid enumerator values. The
compiler optimizes this to a simple range check when enum values
are dense (contiguous), while correctly rejecting invalid values
for sparse enums with gaps in their value ranges.

The --no-enum-validation option on the source subcommand disables
this validation when not needed.

The minimum and maximum fields in _XdrEnum, which were previously
unused placeholders for a range-based validation approach, have
been removed since the switch-based validation handles both dense
and sparse enums correctly.

Because the new mechanism results in substantive changes to
generated code, existing .x files are regenerated. Unrelated white
space and semicolon changes in the generated code are due to recent
commit 1c873a2fd110 ("xdrgen: Don't generate unnecessary semicolon")
and commit 38c4df91242b ("xdrgen: Address some checkpatch whitespace
complaints").

Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfs4xdr_gen.c
fs/nfsd/nfs4xdr_gen.h
include/linux/sunrpc/xdrgen/nfs4_1.h
tools/net/sunrpc/xdrgen/generators/enum.py
tools/net/sunrpc/xdrgen/subcmds/source.py
tools/net/sunrpc/xdrgen/templates/C/enum/decoder/enum.j2
tools/net/sunrpc/xdrgen/templates/C/enum/decoder/enum_be.j2
tools/net/sunrpc/xdrgen/xdr_ast.py
tools/net/sunrpc/xdrgen/xdr_parse.py
tools/net/sunrpc/xdrgen/xdrgen