Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4395075imm; Fri, 18 May 2018 04:31:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqV5Bzbzin63sRgt3uN5Psn5FprLJLYlf5fP/s0Jbu6tItZ1nbFKXCnuM/guJwfqvHdgaRd X-Received: by 2002:a63:7e18:: with SMTP id z24-v6mr7100383pgc.276.1526643108004; Fri, 18 May 2018 04:31:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526643107; cv=none; d=google.com; s=arc-20160816; b=H4mk5W4RqTUGW0hTg6Nlzj8da+7nV7lMVipMqyqWmRlJUTPpzeVPGZlPidAU6iLxRr fHjPnTlBo0Z/i3y+zOvFq08QcNrBjrHFt2bl9t1hPzpQZJn9jJ1hgX70OGNuWy/A/Zan 7TbLIHIw9aL7HVMhvChKM2KKfciqXRYAmVknmHl8Ng9jH4WCLJCzVpbPZ1nPeC/gVOwv WX7Bo5aA8tbMpbwTN4vq25tAXZkZfY+HgvbujkuQzilcEwjWToZs3S3hGg5yt4NKeuhh 6+HhgZRilpEEs56/YODPewXeqPV4o63rbHidpSMvvmuBZtAFyXc++LTOwWhs+4wiU3mq my4Q== 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=PnvUUV9+iPyBbarM/Si0aVEAMHhT+s34E6du0CM0G5c=; b=cBv+2biIgnxrJnsB8oNNR9ZpsWn+tgdCXHLzWwrIzd79JI1p9S7IEbhH8KTlW7FYYZ IolVU/XgZTvKnh02gQXQrt54ecSzx8mmZtgo8zO34JRVPnAkSKi0B00nxMYGIxYH4Npe oGXIy1U1EqkHP8Wp2PW5SOXJfhMGFg8cXiqEvRrQIWrJL8gSJSRpsT2V9Zz5G2Nt+kkp TZsfPvMQrUwrRYe+d1/DqHZk26YOhSjEbSlHPwktiHxrrxmmJyiEnMfrYbTJPQpufZOx nzXr06UQS4jmO8QjLG/2zBEIxpvj2ECJM/Kk/2NZdS09bA4Y0kG0cTYNSZUAbK2dZ2wE 4kUw== 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 a10-v6si7645048pfk.350.2018.05.18.04.31.33; Fri, 18 May 2018 04:31:47 -0700 (PDT) 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 S1752425AbeERLbN (ORCPT + 99 others); Fri, 18 May 2018 07:31:13 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:34672 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751442AbeERLbK (ORCPT ); Fri, 18 May 2018 07:31:10 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4IBSvh6005456 for ; Fri, 18 May 2018 07:31:10 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 2j1vrckjr3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 18 May 2018 07:31:10 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 18 May 2018 12:31:08 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 18 May 2018 12:31:03 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4IBV3Dm35061968 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 18 May 2018 11:31:03 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 50341A4051; Fri, 18 May 2018 12:22:30 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AF501A4040; Fri, 18 May 2018 12:22:28 +0100 (BST) Received: from localhost.localdomain (unknown [9.80.107.246]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 18 May 2018 12:22:28 +0100 (BST) Subject: Re: [PATCH v2 3/9] security: define security_kernel_read_blob() wrapper From: Mimi Zohar To: "Eric W. Biederman" , Casey Schaufler Cc: linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, David Howells , "Luis R . Rodriguez" , kexec@lists.infradead.org, Andres Rodriguez , Greg Kroah-Hartman , Ard Biesheuvel , Kees Cook , Stephen Smalley Date: Fri, 18 May 2018 07:30:50 -0400 In-Reply-To: <87y3ghhbws.fsf@xmission.com> References: <1526568530-9144-1-git-send-email-zohar@linux.vnet.ibm.com> <1526568530-9144-4-git-send-email-zohar@linux.vnet.ibm.com> <74c096ca-1ad1-799e-df3d-7b1b099333a7@schaufler-ca.com> <87y3ghhbws.fsf@xmission.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-GCONF: 00 x-cbid: 18051811-0040-0000-0000-0000045AD902 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051811-0041-0000-0000-000020FF17AC Message-Id: <1526643050.3632.127.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-18_06:,, 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-1805180128 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2018-05-17 at 22:37 -0500, Eric W. Biederman wrote: > Casey Schaufler writes: > > > On 5/17/2018 7:48 AM, Mimi Zohar wrote: > >> In order for LSMs and IMA-appraisal to differentiate between the original > >> and new syscalls (eg. kexec, kernel modules, firmware), both the original > >> and new syscalls must call an LSM hook. > >> > >> Commit 2e72d51b4ac3 ("security: introduce kernel_module_from_file hook") > >> introduced calling security_kernel_module_from_file() in both the original > >> and new syscalls. Commit a1db74209483 ("module: replace > >> copy_module_from_fd with kernel version") replaced these LSM calls with > >> security_kernel_read_file(). > >> > >> Commit e40ba6d56b41 ("firmware: replace call to fw_read_file_contents() > >> with kernel version") and commit b804defe4297 ("kexec: replace call to > >> copy_file_from_fd() with kernel version") replaced their own version of > >> reading a file from the kernel with the generic > >> kernel_read_file_from_path/fd() versions, which call the pre and post > >> security_kernel_read_file LSM hooks. > >> > >> Missing are LSM calls in the original kexec syscall and firmware sysfs > >> fallback method. From a technical perspective there is no justification > >> for defining a new LSM hook, as the existing security_kernel_read_file() > >> works just fine. The original syscalls, however, do not read a file, so > >> the security hook name is inappropriate. Instead of defining a new LSM > >> hook, this patch defines security_kernel_read_blob() as a wrapper for > >> the existing LSM security_kernel_file_read() hook. > > > > What a marvelous opportunity to bikeshed! > > > > I really dislike adding another security_ interface just because > > the name isn't quite right. Especially a wrapper, which is just > > code and execution overhead. Why not change security_kernel_read_file() > > to security_kernel_read_blob() everywhere and be done? > > Nacked-by: "Eric W. Biederman" > > Nack on this sharing nonsense. These two interfaces do not share any > code in their implementations other than the if statement to distinguish > between the two cases. > > Casey you are wrong. We need something different here. > > Mimi a wrapper does not cut it. The code is not shared. Despite using > a single function call today. > > If we want comprehensible and maintainable code in the security modules > we need to split these two pieces of functionality apart. kernel_read_file() is a common, generic method of reading a file from the kernel, which is being called from a number of places.  The kernel_read_file_id enumeration is needed to differentiate between the callers.  The purpose of the new security_kernel_read_file() calls is not for the kernel to read a file, but as a method of identifying the original buffer based methods containing a file. Having to define a separate LSM hook for each of the original, non kernel_read_file(), buffer based method callers, kind of makes sense, as the callers themselves are specific, but is it really necessary? Could we define a new, generic LSM hook named security_kernel_buffer_data() for this purpose? Mimi