Skip to content

Commit

Permalink
tests: fix snap-seccomp-blocks-tty-injection on 32bit systems
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed May 25, 2023
1 parent 362f2db commit f890b2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tests/main/snap-seccomp-blocks-tty-injection/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ execute: |
apparmor_parser -r /var/lib/snapd/apparmor/profiles/snap.test-snapd-sh.sh
fi
snap run test-snapd-sh.sh -c "\$SNAP_COMMON/test-tiocsti" < /dev/tty1 2>&1 | MATCH 'normal TIOCSTI: -1 \(Operation not permitted\)'
snap run test-snapd-sh.sh -c "\$SNAP_COMMON/test-tiocsti" < /dev/tty1 2>&1 | MATCH 'high-bit-set TIOCSTI: -1 \(Operation not permitted\)'
snap run test-snapd-sh.sh -c "\$SNAP_COMMON/test-tiocsti" < /dev/tty1 2>&1 | MATCH 'normal TIOCSTI: -1 \((Operation not permitted|Permission denied)\)'
snap run test-snapd-sh.sh -c "\$SNAP_COMMON/test-tiocsti" < /dev/tty1 2>&1 | MATCH 'high-bit-set TIOCSTI: -1 \((Operation not permitted|Permission denied)\)'
snap run test-snapd-sh.sh -c "\$SNAP_COMMON/test-tioclinux" < /dev/tty1 2>&1 | MATCH 'ioctl\(0, TIOCLINUX, ...\) failed: Permission denied'
12 changes: 10 additions & 2 deletions tests/main/snap-seccomp-blocks-tty-injection/test-tiocsti.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ static int ioctl64(int fd, unsigned long nr, void *arg) {
int main(void) {
int res;
char pushmeback = '#';
res = ioctl64(0, TIOCSTI, &pushmeback);

unsigned long syscallnr = TIOCSTI;
res = ioctl64(0, syscallnr, &pushmeback);
printf("normal TIOCSTI: %d (%m)\n", res);
res = ioctl64(0, TIOCSTI | (1UL<<32), &pushmeback);

#ifdef __LP64__
// this high bit check only works on 64bit systems, on 32bit it will fail:
// "error: left shift count >= width of type [-Werror=shift-count-overflow]"
syscallnr = TIOCSTI | (1UL<<32);
#endif
res = ioctl64(0, syscallnr, &pushmeback);
printf("high-bit-set TIOCSTI: %d (%m)\n", res);
return res;
}

0 comments on commit f890b2f

Please sign in to comment.