Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9610815imu; Wed, 5 Dec 2018 07:33:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/VEVeWFkhYluzzXLUHG5+h1pfz1JZcFmW7P2Rtbju9Wfyjt6+cptawsJCoI+cHPlfnKxqcI X-Received: by 2002:a62:109b:: with SMTP id 27mr24265830pfq.227.1544024030798; Wed, 05 Dec 2018 07:33:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544024030; cv=none; d=google.com; s=arc-20160816; b=DQ850fyQDXGoNUlayVQGZ2k3NYUdb/MC/gnNzNBkKWDHARXhJ3aeSU+L7U5wN81Q1o oMFt/N+Am6s9uxkG/W/GFGWFxjwHM75WWBQVUo00sEX4ENNIrkw/kWWRR2nqUxSP9ulF IhWzTDj4XH79W13nvpW+cl4qhbsTgratKlRbFvgn3ltJ8Vxoxhct6CBSMlwhB/dj8Qix PQyF3B71osI1SUWc1oHBzb9yI2P17ByNcJPwJ140iFbpJB7qxtJGnCYJVM/DRCvVIElf xdj7H2ekPCduSmQ9arwl0iPTG0KsPkvb1I3WW6cfCSL6q8+OQ9PVmJYxljN0vICiV5WH PRbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=sSNwrw4OdIhrzpEGobu5XHr8bur0YNmNbnQ9ZI0M/4U=; b=oEwZ25HmcWjXStA9cFbzDr1R1LVof1Bvhko081nWSWMwKGrTWmQzpTmi2hdO3YmM4E QMDIZ44T6MSrOpZdEaJ0T4nEhRr1DBF5pJAWjnzv0ZEVyh78UjzDYC77CM2vEUzeQe+L 4hkQJn1gg44srrU4lmUgKi1aB64puTa+NHgopzVhY7F11JkvwSuv13++T7G15tmewjdx aBThjT48tU8+mKSSTHB4oC7oiz5oYUrijxCTGnEeQXEP3ADC9l55KOuO9KcssSZcJvLI BQMil8qU2M5ZlAUsx/MSXrinLpU6Ek8MuOG8vb0MwTWj2mpTKgZmZrsCdKElHbSnme3+ EHhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q5si18580302pgg.204.2018.12.05.07.33.35; Wed, 05 Dec 2018 07:33:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727830AbeLEPc6 (ORCPT + 99 others); Wed, 5 Dec 2018 10:32:58 -0500 Received: from mx2.suse.de ([195.135.220.15]:59434 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727103AbeLEPc5 (ORCPT ); Wed, 5 Dec 2018 10:32:57 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 34658B005; Wed, 5 Dec 2018 15:32:55 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 724871E0DBB; Wed, 5 Dec 2018 16:32:54 +0100 (CET) Date: Wed, 5 Dec 2018 16:32:54 +0100 From: Jan Kara To: Alexander Lochmann Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Horst Schirmeier , Jan Kara , linux-block@vger.kernel.org, Jens Axboe Subject: Re: [PATCH] Fix sync. in inode_has_no_xattr() Message-ID: <20181205153254.GD30615@quack2.suse.cz> References: <13eaa1c6-def5-afad-89eb-6f149db90684@tu-dortmund.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <13eaa1c6-def5-afad-89eb-6f149db90684@tu-dortmund.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 05-12-18 12:45:06, Alexander Lochmann wrote: > > inode.i_flags might be altered without proper > synchronisation when the inode belongs to devtmpfs. > The following stacktrace shows how to get there: > 13: entry_SYSENTER_32:460 > 12: do_fast_syscall_32:410 > 11: _static_cpu_has:146 > 10: do_syscall_32_irqs_on:322 > 09: SyS_pwrite64:636 > 08: SYSC_pwrite64:650 > 07: fdput:38 > 06: vfs_write:560 > 05: __vfs_write:512 > 04: new_sync_write:500 > 03: blkdev_write_iter:1977 > 02: __generic_file_write_iter:2897 > 01: file_remove_privs:1818 > 00: inode_has_no_xattr:3163 > > Found by LockDoc (Alexander Lochmann, Horst Schirmeier and Olaf > Spinczyk) > > Signed-off-by: Alexander Lochmann > Signed-off-by: Horst Schirmeier ... > +/* > + * blkdev_write_iter() can call this without i_rwsem, need to be > + * careful with i_flags update. > + */ > static inline void inode_has_no_xattr(struct inode *inode) > { > if (!is_sxid(inode->i_mode) && (inode->i_sb->s_flags & SB_NOSEC)) > - inode->i_flags |= S_NOSEC; > + inode_set_flags(inode, S_NOSEC, S_NOSEC); > } Thinking more about this I'm not sure if this is actually the right solution. Because for example the write(2) can set S_NOSEC flag wrongly when it would race with chmod adding SUID bit. So probably we rather need to acquire i_rwsem in blkdev_write_iter() if file does not have S_NOSEC set (we don't want to acquire it unconditionally as that would heavily impact scalability of block device writes). Honza -- Jan Kara SUSE Labs, CR