From: Jann Horn <jann-XZ1E9jl8jIdeoWH0uzbU5w@public.gmane.org>
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Alexander Viro
<viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>,
linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH] stat.2: add note about stat being racy
Date: Mon, 20 Apr 2015 22:46:01 +0200 [thread overview]
Message-ID: <20150420204601.GA9904@pc.thejh.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 1203 bytes --]
The same thing was fixed for execve() in commit
8b01fc86b9f425899f8a3a8fc1c47d73c2c20543, but for performance
reasons, that simple patch won't work for stat().
---
man2/stat.2 | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/man2/stat.2 b/man2/stat.2
index 0d244af..69ec6a4 100644
--- a/man2/stat.2
+++ b/man2/stat.2
@@ -175,6 +175,29 @@ that may be present between some fields on various architectures.
Consult the glibc and kernel source code
if you need to know the details.
+\# Background: inode attributes are modified with i_mutex held, but
+\# read by stat() without taking the mutex.
+.I Note:
+For performance and simplicity reasons, different fields in the
+.I stat
+structure may contain state information from different moments
+during the execution of the syscall. For example, if
+.IR st_mode ,
+.IR st_uid
+and
+.IR st_gid
+are changed by another process by calling
+.BR chown (2) ,
+.BR stat ()
+might return the old
+.I st_mode
+together with the new
+.IR st_uid ,
+or the old
+.I st_uid
+together with the new
+.IR st_mode .
+
The
.I st_dev
field describes the device on which this file resides.
--
2.1.4
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next reply other threads:[~2015-04-20 20:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-20 20:46 Jann Horn [this message]
[not found] ` <20150420204601.GA9904-J1fxOzX/cBvk1uMJSBkQmQ@public.gmane.org>
2015-04-21 12:44 ` [PATCH] stat.2: add note about stat being racy Michael Kerrisk (man-pages)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150420204601.GA9904@pc.thejh.net \
--to=jann-xz1e9jl8jideowh0uzbu5w@public.gmane.org \
--cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).