From patchwork Mon Apr 20 20:46:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 6244301 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EBAE4BF4A6 for ; Mon, 20 Apr 2015 20:46:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5CFD3202DD for ; Mon, 20 Apr 2015 20:46:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5795C20265 for ; Mon, 20 Apr 2015 20:46:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750771AbbDTUqG (ORCPT ); Mon, 20 Apr 2015 16:46:06 -0400 Received: from thejh.net ([37.221.195.125]:53485 "EHLO thejh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750998AbbDTUqF (ORCPT ); Mon, 20 Apr 2015 16:46:05 -0400 Received: from pc.thejh.net (thejh.net [37.221.195.125]) by thejh.net (Postfix) with ESMTPA id 0E09C180C1B; Mon, 20 Apr 2015 22:46:03 +0200 (CEST) Date: Mon, 20 Apr 2015 22:46:01 +0200 From: Jann Horn To: mtk.manpages@gmail.com Cc: linux-man@vger.kernel.org, Alexander Viro , linux-fsdevel@vger.kernel.org Subject: [PATCH] stat.2: add note about stat being racy Message-ID: <20150420204601.GA9904@pc.thejh.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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.