RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1406395 - strace shows incorrect return value of execve syscall
Summary: strace shows incorrect return value of execve syscall
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: strace
Version: 7.4
Hardware: All
OS: Linux
unspecified
low
Target Milestone: rc
: ---
Assignee: DJ Delorie
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-12-20 12:48 UTC by Michal Kolar
Modified: 2019-07-22 14:54 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-08-30 21:16:11 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Michal Kolar 2016-12-20 12:48:26 UTC
Description of problem:
This is somewhat similar to bz1220802, but this time for rhel7. Strace shows return value of 0 if execve() has passed. But on success, execve() does not return any value, I believe.


Version-Release number of selected component (if applicable)
kernel-3.10.0-514.el7
strace-4.8-11.el7


How reproducible:
always


Steps to Reproduce:
$ strace -eexecve /bin/true


Actual results:
execve("/bin/true", ["/bin/true"], [/* 39 vars */]) = 0
+++ exited with 0 +++


Expected results:
execve("/bin/true", ["/bin/true"], [/* 39 vars */])
+++ exited with 0 +++


Additional info:

Comment 2 Eugene Syromiatnikov 2017-08-06 18:04:22 UTC
I do not see where execve* differ from other system calls (except exit*, of course, which are indeed different), they put their return code the same way as other system calls do, and strace indeed retrieves and shows it. I assume, process (right at the entry point) can check it as well as return code of any other system call (I'm not saying that it may be useful, however).

Comment 3 DJ Delorie 2017-08-08 20:55:40 UTC
Except execve*() doesn't have a return code when it doesn't return (i.e. when it successfully exec's a new process).  A return code shouldn't be printed at all in that case.  This is similar to how exit() is handled.

If execve*() fails to exec a process, then yes, the return value should be reported just like any other syscall.

Comment 4 Eugene Syromiatnikov 2017-08-09 11:05:07 UTC
Well, what I see in [1], which is called from [2], which is called from [3], is a bunch of work related to process image replacement, with a return at the end in case of success [4]. The fact that the old process image is non-existent at the moment of return is a minor detail, which is unrelated to the fact that syscall does return (to the entry point of the new image). And, at the moment execve() returns, ptrace syscall-exit-stop occurs and strace is notified about it (note that PTRACE_EVENT_EXEC is largely ignored and is used mostly for handling possible pid change on old kernels and supporting detach-on-execve functionality). So, the fact that strace prints 11 as execve return code means that something is not good (ELF loader explicitly sets retval to 0 at the end of load, so it's probably different image format or something else, maybe something on arch-specific exit path).

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/exec.c#n1682
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/exec.c#n1828
[3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/exec.c#n1910
[4] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/exec.c#n1804

Comment 5 DJ Delorie 2017-08-09 16:29:24 UTC
If execv fails for any reason, sure, print a return code.

As for the success case, which is all this issue is about, the "minor detail" about the caller not existing is the crux of the issue - the call the caller makes doesn't return to the caller.  IMHO this is all about the traced process's point of view, since that's the expectation the strace user has.  But, if we've gotten to this point in the philosophy, it's time to bring the issue up upstream and let them decide which semantics make more sense for the typical user.

Also, if the value of zero is just a coincidence (the 11 from bz1220802 indicates this might be so), then printing arbitrary values is still a bug.  However, I've posted the philosophical part of the question upstream:

https://sourceforge.net/p/strace/mailman/message/35989051/

Comment 6 DJ Delorie 2017-08-30 21:16:11 UTC
The result of the upstream discussion is that execve *does* return a success code, despite the code being returned to the new image and not the old one (and being difficult, but not impossible, to access), and thus printing " = 0" is appropriate.

I.e. strace is considering the call from the kernel's point of view, not the POSIX C API point of view.

Comment 7 Eugene Syromiatnikov 2019-07-22 14:54:26 UTC
(In reply to DJ Delorie from comment #5)
> https://sourceforge.net/p/strace/mailman/message/35989051/

A note to myself: this thread in the mail list archive on lists.strace.io:

https://lists.strace.io/pipermail/strace-devel/2017-August/007230.html


Note You need to log in before you can comment on or make changes to this bug.