Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751263AbdIQFsD (ORCPT ); Sun, 17 Sep 2017 01:48:03 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55386 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750746AbdIQFsB (ORCPT ); Sun, 17 Sep 2017 01:48:01 -0400 Subject: Re: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description) From: Mimi Zohar To: Linus Torvalds Cc: LSM List , Christoph Hellwig , linux-ima-devel@lists.sourceforge.net, Christoph Hellwig , James Morris , Linux Kernel Mailing List , Matthew Garrett , Jan Kara , "Theodore Ts'o" , Andreas Dilger , Jaegeuk Kim , Chao Yu , Steven Whitehouse , Bob Peterson , David Woodhouse , Dave Kleikamp , Ryusuke Konishi , Mark Fasheh , Joel Becker , Richard Weinberger , "Darrick J. Wong" , Hugh Dickins , Chris Mason Date: Sun, 17 Sep 2017 01:47:41 -0400 In-Reply-To: References: <1505451494-30228-1-git-send-email-zohar@linux.vnet.ibm.com> <1505451494-30228-4-git-send-email-zohar@linux.vnet.ibm.com> <1505507142.4200.103.camel@linux.vnet.ibm.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.5 (3.20.5-1.fc24) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-MML: disable x-cbid: 17091705-0016-0000-0000-0000026523D1 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17091705-0017-0000-0000-000006EA48CC Message-Id: <1505627261.4200.161.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-09-17_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1709170083 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1742 Lines: 39 On Sat, 2017-09-16 at 11:20 -0700, Linus Torvalds wrote: > On Fri, Sep 15, 2017 at 1:25 PM, Mimi Zohar wrote: > > > > To resolve this locking problem, this patch defines a new > > ->integrity_read file operation method, which is equivalent to > > ->read_iter, except that it will not take the i_rwsem lock, but will > > be called with the i_rwsem held exclusively. > > > > Since taking the i_rwsem exclusively is not required for reading the > > file in order to calculate the file hash, the code only verifies > > that the lock has been taken. > > Ok, so I'm onboard with the commit message now, but realized that I'm > not actually convinced that i_rwsem is even meaningful. > > Sure, generic_file_write_iter() does take that lock exclusively, but > not everybody uses generic_file_write_iter() at all for writing. > For example, xfs still uses that i_rwsem, but for block-aligned writes > it will only get it shared. And I'm not convinced some other > filesystem might not end up using some other lock entirely. > > So I'm basically not entirely convinced that these i_rwsem games make > any sense at all. > > The filesystem can do its own locking, and I'm starting to think that > it would be better to just pass this "this is an integrity read" down > to the filesystem, and expect the filesystem to do the locking based > on that. IMA would still need to take the i_rwsem to write the xattr.  Unless the i_rwsem was taken before calling the integrity_read, calculating the file hash would be serialized, but would not prevent the file hash from being calculated multiple times. (Introducing a new lock would result in the locks being taken in reverse order for setxattr, chown, chmod syscalls.) Mimi