Skip to content

Commit

Permalink
Ignore EPERM for root when setting IMA signature xattr
Browse files Browse the repository at this point in the history
This lets installations succeed even if the ima plugin happens to be
installed in a rootless container, where IMA isn't supported. We can't
specifically test for rootless container, but I don't know what other
situation would result in EPERM for root when setting IMA so it seems
like a reasonable heuristic for this.

Testing this is a bit tricky: we expect the install to succeed in all cases,
but whether IMA actually gets set depends on the container.

Fixes: #3234
  • Loading branch information
pmatilai committed Jan 13, 2025
1 parent 48da1fc commit 7617171
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plugins/ima.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ static rpmRC ima_fsm_file_prepare(rpmPlugin plugin, rpmfi fi, int fd,
else
xx = lsetxattr(path, XATTR_NAME_IMA, fsig, len, 0);
if (xx < 0) {
int is_err = errno != EOPNOTSUPP;
/* unsupported fs or root inside rootless container? */
int is_err = !(errno == EOPNOTSUPP ||
(errno == EPERM && getuid() == 0));

rpmlog(is_err?RPMLOG_ERR:RPMLOG_DEBUG,
"ima: could not apply signature on '%s': %s\n",
Expand Down
25 changes: 25 additions & 0 deletions tests/rpmsigdig.at
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,31 @@ rpm -qp --qf "[%{filenames}:%{filesignatures}\n]" /tmp/hello-1.0-1.src.rpm
hello-1.0.tar.gz:(none)
],
[])

# Test that installing an ima signed package works.
# The installation should succeed in all cases, but whether setting the
# IMA signature succeeds depends on container privileges - in rootless
# we can't do this.
RPMTEST_CHECK([
runroot rpm -U /data/RPMS/imatest-1.0-1.fc34.noarch.rpm

cat << EOF > imaout
# file: /usr/share/example1
security.ima=0sAwIEpZglVABIMEYCIQDlEXva+nO6rrHx3EbsqkaYGmLUF3RaM1MlcrY9xtldFgIhAMeJEHrFuR4tkV4d88e3hBT2s/UImdRMHeOB0Ok438gr
EOF

touch canary
if setfattr -n security.ima canary 2> /dev/null; then
cp imaout expout
else
touch expout
fi
runroot_other getfattr --absolute-names -m security.ima /usr/share/example1
],
[0],
[expout],
[])

RPMTEST_CLEANUP


Expand Down

0 comments on commit 7617171

Please sign in to comment.