Skip to content

linux: error on invalid capabilities in config.json#2144

Open
Rajkaran-122 wants to merge 1 commit into
containers:mainfrom
Rajkaran-122:validate-capabilities-2121
Open

linux: error on invalid capabilities in config.json#2144
Rajkaran-122 wants to merge 1 commit into
containers:mainfrom
Rajkaran-122:validate-capabilities-2121

Conversation

@Rajkaran-122

Copy link
Copy Markdown

Description:
Instead of silently ignoring invalid capability strings found in config.json during parsing, crun will now correctly return an error.

This prevents containers from starting up in a potentially unexpected or under-privileged state if the user makes a typo in their capabilities configuration.

Fixes: #2121

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@packit-as-a-service

Copy link
Copy Markdown

Ephemeral COPR build failed. @containers/packit-build please check.

@giuseppe giuseppe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a comment,

make sure to use your real name/email to sign-off the commit.

Run make clang-format before submitting the patch

Comment thread src/libcrun/linux.c Outdated
Comment on lines +4346 to +4350
if (read_caps (caps.effective, capabilities->effective, capabilities->effective_len, err) < 0) return -1;
if (read_caps (caps.inheritable, capabilities->inheritable, capabilities->inheritable_len, err) < 0) return -1;
if (read_caps (caps.ambient, capabilities->ambient, capabilities->ambient_len, err) < 0) return -1;
if (read_caps (caps.bounding, capabilities->bounding, capabilities->bounding_len, err) < 0) return -1;
if (read_caps (caps.permitted, capabilities->permitted, capabilities->permitted_len, err) < 0) return -1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the same pattern used in the rest of the code.

Use int ret and return ret so we propagate the same return code.

@Rajkaran-122
Rajkaran-122 force-pushed the validate-capabilities-2121 branch 2 times, most recently from 5f50805 to 8075432 Compare July 27, 2026 08:37
Instead of silently ignoring invalid capability strings in config.json,
return an error. This prevents containers from starting without the
intended privileges due to typos.

Fixes: containers#2121

Signed-off-by: Rajkaran <yadavrajkaran854@gmail.com>
@Rajkaran-122
Rajkaran-122 force-pushed the validate-capabilities-2121 branch from 8075432 to 410308d Compare July 27, 2026 09:22
Comment thread src/libcrun/linux.c
read_caps (caps.bounding, capabilities->bounding, capabilities->bounding_len);
read_caps (caps.permitted, capabilities->permitted, capabilities->permitted_len);
ret = read_caps (caps.effective, capabilities->effective, capabilities->effective_len, err);
if (ret < 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these if (ret < 0) could benefit from being if (UNLIKELY (ret < 0))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid or malformed capability strings are silently ignored

2 participants