Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3898945imm; Thu, 17 May 2018 17:25:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoT2C0pld6le6shtmVUjzex800Fs1GeA35UB267u3higSIAP+W267CkCOiaqS6/6JDvaXMt X-Received: by 2002:a63:b647:: with SMTP id v7-v6mr5512926pgt.181.1526603131596; Thu, 17 May 2018 17:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526603131; cv=none; d=google.com; s=arc-20160816; b=mFxkeOjN3umZ03yPxoxALnMQEVyvdRzzn837fAtS0RCzYZV3b6gcl+FmEmQVmPvioi AeLc2Vrm5BqfUlymM1WQ5kBzdBHhm4b0ns9+KLFBglSHBkAtDaOh3KVfdsdgdfU7C5cD DopUI0qvXxZjdbBw6xSxFmNKcnUT2jtgdiCiW0+PI0pkaXSjeBTCjaCTlJHbdvYD2S/2 Tj0XUda7kVMYd0F9d+eQG16pdQGAC5tY3XTg7qgRBUrgZqlLTM2dOIIfyjhK/GyOHiqD PiMqmiprmsDFqBn0i23CaGI6aTuMJf4lt1mVZ7JC8NkVjOr5otA/J/OXGEVJMPM2I1f0 WmKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=Hn2UaiWgiClEk1OIfSkB21wepK0Bazi0hGIkS0gxcCA=; b=jmMCrin99zgMHUNc03tFxqPjkFvTWCCWYRK2LcGD8JSK3oieVMXorMErsNX8+avslD vEqm9tCFcnXxry2GtcvieP/a00+QWDV+0TFibf2K6BVVOaazz8n8N2b+0LQmJb7ReWaQ Ak+/a9foVZq7zrqIRUtDvsQeNiTeRouqhnwXf+OeDqJckVyw7XXcGE55fCU2ySdkQbSN 8oHhuQBPHTLhsEfOA9vmi/x31SZ1WaSvacoJibxiDEHfyLEN/tbQzvqwf8oyUiG9Rf11 dLFsrJGMWESLVRCJrxTb+p4y6KFcw1aBItT9KZfyML55lgZM5/4PNpvNTnoVtPCL8AkA tnCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=t4c5z3VC; 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 h68-v6si4920735pgc.579.2018.05.17.17.25.17; Thu, 17 May 2018 17:25:31 -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; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=t4c5z3VC; 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 S1752457AbeERAYq (ORCPT + 99 others); Thu, 17 May 2018 20:24:46 -0400 Received: from sonic306-28.consmr.mail.ne1.yahoo.com ([66.163.189.90]:44051 "EHLO sonic306-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752447AbeERAYm (ORCPT ); Thu, 17 May 2018 20:24:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1526603081; bh=Hn2UaiWgiClEk1OIfSkB21wepK0Bazi0hGIkS0gxcCA=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=t4c5z3VCzufF/1fVtTMSenYr+uD6ztE2rJgO3j37gy2nRZQKmKmNRNvDIQe5dRq7FabT2G4/g2RM9V6nI7gleAT29YN+LJGZUU4L6aJWGT6WW1jw1643F9ctW3M8YGpiXSPfCFIY4KHHeJ4K34HBx6e3f4J+1MeLq4DywgRZ/1VPs5GJjWOed1CkLc90egCd+yligCsyTkj+EUScgeR2IXKQ79L0q77I0SCcwlJCKG8wmRshZyZioIkyEx8zt19zVgvjEVy2pbEtsxhS/7w2t3a4k8UH6MwQ1xwdzzBD4Lk3+qMnfLYnLaxc94/acigimSTOL2DH46ZZhvhs5xrnjg== X-YMail-OSG: RdrzShUVM1nVF5Z.LMKCv3_qU2cluqY4seE00vDkPs_UPjctaVqsFfP5sIPwhcL Y87gXebPrqh2_0ius86D0ssSMukZWnNxoQm0jXiLla14dEEG92rXCTf1K72OpKWSOg0jI1fISTBi OD4374ON63AvwbO6T2jaXQr.LCLw7qztLHQ3YVH24BAvPsDO5p8T0gxjvoWpLk36PaFgW2asKokz wDQ2DatSqU.cSccKsHzrexcY24rvZG1khPwxAAtv2AHTDtEuh6wJRNKNaRhgDEPx2fYgXLQTGyT2 prX4K.h8tCQhWyoC3K.aWmdIxFxOxa91ZjxZPecYHgm8t6lg6Oq8U4gf5sqEkGzkflVEWDeSCDhb ISYBdbvNlaNRGw5WX57Y353ORnPiaw0GUnWhc40pJH6GcY8CBXShE0a_XF6OqBV1rcLgicGlSf1o iDJDarNu6VJaqCQL7Y0DQUC.9ncxe28I3RXdh.pq9i1O5Pit_vzimWKw1rohfMBwqE8OlbCXNjZ. iHT8FgzL0PcM8_ns.oKRg7T9y3JkpoRNHAhDCeLS9P5E_8keGWbc9yrvgf6LpI9osKkJDjZt5FaN x3tkW23R__vqAezIlS2nH0pBfsi.XfA7TBBV1lJHOgC1L1tpzsr.d14M7sk42nOi51hFvK6BjPK7 2_.0CzHF.jw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ne1.yahoo.com with HTTP; Fri, 18 May 2018 00:24:41 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO [192.168.0.105]) ([67.169.65.224]) by smtp423.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID fe7b67ded8a980389473498956168c26; Fri, 18 May 2018 00:24:39 +0000 (UTC) Subject: Re: [PATCH v2 3/9] security: define security_kernel_read_blob() wrapper To: Mimi Zohar , linux-integrity@vger.kernel.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, David Howells , "Luis R . Rodriguez" , Eric Biederman , kexec@lists.infradead.org, Andres Rodriguez , Greg Kroah-Hartman , Ard Biesheuvel , Kees Cook References: <1526568530-9144-1-git-send-email-zohar@linux.vnet.ibm.com> <1526568530-9144-4-git-send-email-zohar@linux.vnet.ibm.com> From: Casey Schaufler Message-ID: <74c096ca-1ad1-799e-df3d-7b1b099333a7@schaufler-ca.com> Date: Thu, 17 May 2018 17:24:36 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1526568530-9144-4-git-send-email-zohar@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > > Signed-off-by: Mimi Zohar > Cc: Eric Biederman > Cc: Luis R. Rodriguez > Cc: Kees Cook > Cc: David Howells > Cc: Casey Schaufler > > Changelog v2: > - Define a generic wrapper named security_kernel_read_blob() for > security_kernel_read_file(). > > Changelog v1: > - Define and call security_kexec_load(), a wrapper for > security_kernel_read_file(). > --- > include/linux/security.h | 6 ++++++ > security/security.c | 6 ++++++ > 2 files changed, 12 insertions(+) > > diff --git a/include/linux/security.h b/include/linux/security.h > index 63030c85ee19..4db1967a688b 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -323,6 +323,7 @@ int security_kernel_module_request(char *kmod_name); > int security_kernel_read_file(struct file *file, enum kernel_read_file_id id); > int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, > enum kernel_read_file_id id); > +int security_kernel_read_blob(enum kernel_read_file_id id); > int security_task_fix_setuid(struct cred *new, const struct cred *old, > int flags); > int security_task_setpgid(struct task_struct *p, pid_t pgid); > @@ -922,6 +923,11 @@ static inline int security_kernel_post_read_file(struct file *file, > return 0; > } > > +static inline int security_kernel_read_blob(enum kernel_read_file_id id) > +{ > + return 0; > +} > + > static inline int security_task_fix_setuid(struct cred *new, > const struct cred *old, > int flags) > diff --git a/security/security.c b/security/security.c > index 68f46d849abe..8f199b2bf4a2 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -1044,6 +1044,12 @@ int security_kernel_read_file(struct file *file, enum kernel_read_file_id id) > } > EXPORT_SYMBOL_GPL(security_kernel_read_file); > > +int security_kernel_read_blob(enum kernel_read_file_id id) > +{ > + return security_kernel_read_file(NULL, id); > +} > +EXPORT_SYMBOL_GPL(security_kernel_read_blob); > + > int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, > enum kernel_read_file_id id) > {