Received: by 10.223.185.111 with SMTP id b44csp797808wrg; Fri, 9 Mar 2018 14:01:20 -0800 (PST) X-Google-Smtp-Source: AG47ELsiG6HDMXeJPaJ8/nYuK6fPZ2ytEqSqrdrpeNKNhIMD8JqD8U/Cl4zHK+8iOefxdl8AkQvr X-Received: by 2002:a17:902:8bc2:: with SMTP id r2-v6mr29054000plo.213.1520632880255; Fri, 09 Mar 2018 14:01:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520632880; cv=none; d=google.com; s=arc-20160816; b=KSvUpAN6WxMiTHcd4s97meZSA4U0dlGv91wJt5+KTrnZaB7filDU1kLLNyaJ8Z9r1J mIwTLURO6ehnlKijLQCK97PRB6JWbQJbJF9ViHKYGceskhsTABclOCu5VSfRX4JcMPsV HhgttjzA8p90lbTXniUiH7eBFL3D8+HXHHJFPL70ilsK2SQU5qw0Bj+KEj5+28BzE+XV N/4X+xO6Trqm25gvbTO/n209xWr30XTLXLHZXckmsbY7O1i19XdcklWsKR3DFzr94EMB UZIV/kjyHyK5la2X2MX/ldrutiKhZt9Z7ngqe7yHLL55TGNM/Ul/RNXkRJ3dQ1QWnEIv d8+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:cc:to:from:subject :arc-authentication-results; bh=W4qs5L+nkG+tKgDK2ImdqiRMJIm2+V3QeQ84Zv6l/0k=; b=mTKwCbEQxVUlGat6tqwJ2k5dzKag+ecQbjt05O2mGNl7tw+0RNQ23t+4LucZJ+OSFu vtdNJfGxb6PA6VRh1wCUGETbpM0elqfvrfY4YBjmgIIA6tJJKdtqHJtFKRKbXiKVRRhc 1hd/VsWT3TWmSz72mSqX+M1hxqvN/O0V49HfyreNcJ9yZlRaP36khMDcjGLrxWNRb8O8 jqZluE3sH8Ut1otGNtOmXrdFsEs2r5j7aR+PZIGUVBnbiKDMdtvKz8TeMgLgCIwHrEr7 OD/zSzJWpEPjJIQTKZGeXv1zx/nECgxFrcJ9FyNcaRtTXqNvkG1EIVgH7QgwAVPMSi6n iJYg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b10-v6si1534167plx.355.2018.03.09.14.01.04; Fri, 09 Mar 2018 14:01:20 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932773AbeCIV7l (ORCPT + 99 others); Fri, 9 Mar 2018 16:59:41 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38588 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932206AbeCIV7i (ORCPT ); Fri, 9 Mar 2018 16:59:38 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w29LxIUV125074 for ; Fri, 9 Mar 2018 16:59:37 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gkyfd6w2d-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Fri, 09 Mar 2018 16:59:37 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Mar 2018 21:54:34 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 9 Mar 2018 21:54:30 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w29LsUa663373414; Fri, 9 Mar 2018 21:54:30 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D8715203F; Fri, 9 Mar 2018 20:46:05 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.101.51]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 2AE2B52045; Fri, 9 Mar 2018 20:46:04 +0000 (GMT) Subject: Re: [PATCH v2] exec: Set file unwritable before LSM check From: Mimi Zohar To: Kees Cook , Linus Torvalds Cc: James Morris , Linux Kernel Mailing List , LSM List , "Serge E. Hallyn" , linux-integrity , Paul Moore , Stephen Smalley Date: Fri, 09 Mar 2018 16:54:27 -0500 In-Reply-To: References: <20180309193020.GA5149@beast> 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-GCONF: 00 x-cbid: 18030921-0012-0000-0000-000005BAFE07 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18030921-0013-0000-0000-00001937240B Message-Id: <1520632467.3911.49.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-09_11:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803090260 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-03-09 at 11:54 -0800, Kees Cook wrote: > On Fri, Mar 9, 2018 at 11:47 AM, Linus Torvalds > wrote: > > On Fri, Mar 9, 2018 at 11:30 AM, Kees Cook wrote: > >> The LSM check should happen after the file has been confirmed to be > >> unchanging. Without this, we could have a race between the Time of Check > >> (the call to security_kernel_read_file() which could read the file and > >> make access policy decisions) and the Time of Use (starting with > >> kernel_read_file()'s reading of the file contents). In theory, file > >> contents could change between the two. For files opened by userspace, IMA refers to the problem as "Time of Measure, Time of Use" (ToMToU) and emits an audit message. security_kernel_read_file() is being called by the kernel to read the kexec kernel image and initramfs, kernel modules (new syscall), ima_policy, EVM x509 certificate, and firmware. If these files are signed, like they should be, then IMA prevents them from being opened for write.  Modifying the file via the filesystem should not be possible.  Other sorts of attacks, would probably be possible. If these files aren't signed, then in terms of IMA-measurement the file measured, might not be the file used.  The ToMToU audit message is not being generated for these files. > > I'm going to assume I get this for 4.17 from the security tree. > > > > Because I'm guessing there are actually no existing users that care? > > selinux seems to just look at file state, not actually at contents or > > anything that write access denial would care about. > > > > And the only other security module that even registers this is > > loadpin, and again it just seems to check things like "on the right > > filesystem" that aren't actually impacted by write access (in fact, > > the documented reason is to check that it's a read-only filesystem so > > that write access is simply _irrelevant_). > > > > So this issue seems to be mainly a cleanliness thing, not an actual bug. > > That is my assumption too (I left off the Cc: stable as a result). I'm > much less familiar with IMA, though, but it's a caller of > kernel_read_file(), not hooking it, etc. Please add my reviewed-by. Mimi