Inaccurate errno reporting in ptrace attach error messages

Bug #1934906 reported by Seth Forshee
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gdb (Ubuntu)
New
Undecided
Unassigned

Bug Description

Ubuntu carries a patch for gdb, ptrace-error-verbosity.patch, to print some extra information about why attaching to a process might have failed. This inserts a fprintf_unfiltered() call between the ptrace() and the corresponding perror(). Recently something has changed which causes errno to be set to ENOTTY after the failed ptrace but before calling perror(). It's clear that the ptrace() errno is EPERM, since that's the only condition which will print the extra information, however the error message printed is "Inappropriate ioctl for device".

Using strace I observed failing tty ioctls which seem to be responsible:

ptrace(PTRACE_ATTACH, 11538) = -1 EPERM (Operation not permitted)
ioctl(2, TCGETS, 0x7fff1d9c2590) = -1 ENOTTY (Inappropriate ioctl for device)
write(2, "Could not attach to process. If"..., 221Could not attach to process. If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf
) = 221
ioctl(2, TCGETS, 0x7fff1d9c2590) = -1 ENOTTY (Inappropriate ioctl for device)
...
ioctl(1, TCSBRK, 1) = -1 ENOTTY (Inappropriate ioctl for device)
...
write(2, "ptrace: Inappropriate ioctl for "..., 39ptrace: Inappropriate ioctl for device.) = 39

Our qa-regression-testing kernel security tests include some ptrace tests which expect attach to fail with an "Operation not permitted" error message. So in addition to being inaccurate, this change in behavior is causing kernel regression testing to fail.

This behavior can be reproduced using scripts/test-kernel-security.py from qa-regression-testing.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.