Re: [PATCH v5 4/9] livepatch: Implement replace set for scoped atomic replace

[email protected]
Newsgroups org.kernel.vger.live-patching
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The `--provides` argument in `klp-build` lacks input validation, allowing shell command injection during the kernel module build process.
--

--- Patch [4]: [PATCH v5 4/9] livepatch: Implement replace set for scoped atomic replace ---
commit 1fb78be5e32d18ecfd4bbeb7fa484d70bf6b9401
Author: Yafang Shao <[email protected]>

livepatch: Implement replace set for scoped atomic replace

This commit introduces a more flexible model for livepatch replacement by
adding provides and obsoletes fields, allowing multiple independent 
livepatch sets to coexist on the same system.

> diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
> index c4a7acf8edc3f..3600f93d9c1c3 100755
> --- a/scripts/livepatch/klp-build
> +++ b/scripts/livepatch/klp-build

[ ... ]

> @@ -189,9 +190,26 @@ process_args() {
>  				NAME="$(module_name_string "$NAME")"
>  				shift 2
>  				;;
> -			--no-replace)
> -				REPLACE=0
> -				shift
> +			-p | --provides)
> +				PROVIDES="$2"

[Severity: Medium]
Is there a missing validation check for the provides argument here?

The obsoletes argument below checks for valid integers, but it appears this
assignment accepts any unvalidated string.

> +				shift 2
> +				;;
> +			-r | --obsoletes)
> +				OBSOLETES="$2"
> +				local obs_val="$2"
> +				[[ "$obs_val" != \[*\] ]] && die "obsoletes must be enclosed in brackets, e.g., '[0,1,2]'"

[ ... ]

> @@ -847,7 +896,17 @@ build_patch_module() {
>  
>  	cflags=("-ffunction-sections")
>  	cflags+=("-fdata-sections")
> -	[[ $REPLACE -eq 0 ]] && cflags+=("-DKLP_NO_REPLACE")
> +	cflags+=("-DKLP_PROVIDES=$PROVIDES")

[Severity: Medium]
Because the provides argument lacks validation in process_args(), could
this assignment allow shell command injection during the build process if 
un-escaped metacharacters are passed to the script?

> +
> +	# Process OBSOLETES: remove brackets and spaces, convert to comma-separated string
> +	# Input: "[0, 1, 2]" or "[]" or "" -> Output: "0,1,2" or empty
> +	if [[ -n "$OBSOLETES" && "$OBSOLETES" != "[]" ]]; then

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.