Skip to content

Commit 7bf194e

Browse files
committed
Ignore EPERM for root when setting IMA signature xattr
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
1 parent 48da1fc commit 7bf194e

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

plugins/ima.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ static rpmRC ima_fsm_file_prepare(rpmPlugin plugin, rpmfi fi, int fd,
7171
else
7272
xx = lsetxattr(path, XATTR_NAME_IMA, fsig, len, 0);
7373
if (xx < 0) {
74-
int is_err = errno != EOPNOTSUPP;
74+
/* unsupported fs or root inside rootless container? */
75+
int is_err = !(errno == EOPNOTSUPP ||
76+
(errno == EPERM && getuid() == 0));
7577

7678
rpmlog(is_err?RPMLOG_ERR:RPMLOG_DEBUG,
7779
"ima: could not apply signature on '%s': %s\n",

tests/rpmsigdig.at

+31
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,37 @@ hello-1.0.tar.gz:(none)
18911891
[])
18921892
RPMTEST_CLEANUP
18931893

1894+
# Test that installing an ima signed package works.
1895+
# The installation should succeed in all cases, but whether setting the
1896+
# IMA signature succeeds depends on container privileges - in rootless
1897+
# we can't do this.
1898+
AT_SETUP([install ima file signatures])
1899+
AT_KEYWORDS([install ima signature])
1900+
AT_SKIP_IF([$IMA_DISABLED])
1901+
1902+
RPMTEST_SETUP
1903+
1904+
cat << EOF > expout
1905+
# file: /usr/share/example1
1906+
security.ima=0sAwIEpZglVABIMEYCIQDlEXva+nO6rrHx3EbsqkaYGmLUF3RaM1MlcrY9xtldFgIhAMeJEHrFuR4tkV4d88e3hBT2s/UImdRMHeOB0Ok438gr
1907+
1908+
EOF
1909+
1910+
touch canary
1911+
# different expectations in a rootless container
1912+
if ! setfattr -n security.ima canary 2> /dev/null; then
1913+
rm expout
1914+
touch expout
1915+
fi
1916+
1917+
RPMTEST_CHECK([
1918+
runroot rpm -U /data/RPMS/imatest-1.0-1.fc34.noarch.rpm
1919+
runroot_other getfattr --absolute-names -d -m security.ima /usr/share/example1
1920+
],
1921+
[0],
1922+
[expout],
1923+
[])
1924+
RPMTEST_CLEANUP
18941925

18951926
AT_SETUP([--delsign with misplaced ima signature])
18961927
AT_KEYWORDS([rpmsign ima signature])

0 commit comments

Comments
 (0)