xdrgen: Add enum value validation to generated decodersXDR enum decoders generated by xdrgen do not verify that incomingvalues are valid members of the enum. Incoming out-of-range valuesfrom mali
xdrgen: Add enum value validation to generated decodersXDR enum decoders generated by xdrgen do not verify that incomingvalues are valid members of the enum. Incoming out-of-range valuesfrom malicious or buggy peers propagate through the systemunchecked.Add validation logic to generated enum decoders using a switchstatement that explicitly lists valid enumerator values. Thecompiler optimizes this to a simple range check when enum valuesare dense (contiguous), while correctly rejecting invalid valuesfor sparse enums with gaps in their value ranges.The --no-enum-validation option on the source subcommand disablesthis validation when not needed.The minimum and maximum fields in _XdrEnum, which were previouslyunused placeholders for a range-based validation approach, havebeen removed since the switch-based validation handles both denseand sparse enums correctly.Because the new mechanism results in substantive changes togenerated code, existing .x files are regenerated. Unrelated whitespace and semicolon changes in the generated code are due to recentcommit 1c873a2fd110 ("xdrgen: Don't generate unnecessary semicolon")and commit 38c4df91242b ("xdrgen: Address some checkpatch whitespacecomplaints").Reviewed-by: NeilBrown <neil@brown.name>Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
show more ...
xdrgen: Implement big-endian enumsSigned-off-by: Chuck Lever <chuck.lever@oracle.com>
xdrgen: Rename "enum yada" types as just "yada"This simplifies the generated C code and makes way for supportingbig-endian XDR enums.Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
tools: Add xdrgenAdd a Python-based tool for translating XDR specifications into XDRencoder and decoder functions written in the Linux kernel's C codingstyle. The generator attempts to match the
tools: Add xdrgenAdd a Python-based tool for translating XDR specifications into XDRencoder and decoder functions written in the Linux kernel's C codingstyle. The generator attempts to match the usual C coding style ofthe Linux kernel's SunRPC consumers.This approach is similar to the netlink code generator intools/net/ynl .The maintainability benefits of machine-generated XDR code include:- Stronger type checking- Reduces the number of bugs introduced by human error- Makes the XDR code easier to audit and analyze- Enables rapid prototyping of new RPC-based protocols- Hardens the layering between protocol logic and marshaling- Makes it easier to add observability on demand- Unit tests might be built for both the tool and (automatically) for the generated codeIn addition, converting the XDR layer to use memory-safe languagessuch as Rust will be easier if much of the code can be convertedautomatically.Tested-by: Jeff Layton <jlayton@kernel.org>Signed-off-by: Chuck Lever <chuck.lever@oracle.com>