From patchwork Thu Mar 1 12:38:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 10251139 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 70527602B5 for ; Thu, 1 Mar 2018 12:38:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D23028EAA for ; Thu, 1 Mar 2018 12:38:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51A0029043; Thu, 1 Mar 2018 12:38:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB74A28EAA for ; Thu, 1 Mar 2018 12:38:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030391AbeCAMit (ORCPT ); Thu, 1 Mar 2018 07:38:49 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:44627 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030363AbeCAMit (ORCPT ); Thu, 1 Mar 2018 07:38:49 -0500 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1erNTz-0007ss-Li; Thu, 01 Mar 2018 13:38:47 +0100 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.90_1) (envelope-from ) id 1erNTz-0007Rb-4G; Thu, 01 Mar 2018 13:38:47 +0100 From: Sascha Hauer To: linux-integrity@vger.kernel.org Cc: Mimi Zohar , Sascha Hauer Subject: [PATCH] evm: check for remount ro in progress before writing Date: Thu, 1 Mar 2018 13:38:45 +0100 Message-Id: <20180301123845.26189-1-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.16.1 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-integrity@vger.kernel.org Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP EVM might update the evm xattr while the VFS performs a remount to readonly mode. This is not properly checked for, additionally check the s_readonly_remount superblock flag before writing. The bug can for example be observed with UBIFS. UBIFS checks the free space on the device before and after a remount. With EVM enabled the free space sometimes differs between both checks. Signed-off-by: Sascha Hauer --- security/integrity/evm/evm_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c index a8d502827270..4a147a998aa7 100644 --- a/security/integrity/evm/evm_main.c +++ b/security/integrity/evm/evm_main.c @@ -185,6 +185,7 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry, iint->flags |= EVM_IMMUTABLE_DIGSIG; evm_status = INTEGRITY_PASS_IMMUTABLE; } else if (!IS_RDONLY(d_backing_inode(dentry)) && + !(dentry->d_inode->i_sb->s_readonly_remount) && !IS_IMMUTABLE(d_backing_inode(dentry))) { evm_update_evmxattr(dentry, xattr_name, xattr_value,