From patchwork Tue Aug 20 00:18:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 11102399 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 600451395 for ; Tue, 20 Aug 2019 00:19:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3FFBE2087E for ; Tue, 20 Aug 2019 00:19:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YkyEhMJN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728615AbfHTAT3 (ORCPT ); Mon, 19 Aug 2019 20:19:29 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:46932 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729215AbfHTAT0 (ORCPT ); Mon, 19 Aug 2019 20:19:26 -0400 Received: by mail-qk1-f201.google.com with SMTP id c79so5229311qkg.13 for ; Mon, 19 Aug 2019 17:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=B4yWHzIV2L8DYHsuCwQr8Jl+t6iWEiT99YB+g+PxVJ0=; b=YkyEhMJNW5K8R8PGvqzm9AWtlOyUSRLd1552j5/1Nm456iPghSLb/0BGVlLwy4pBPB WEtFg0QKJbHgxQihV165tQFP4cdLcCGCJTIDnKhXi0DjmrB10qp+mDKdIh1Nnv94Zsb7 qlxFB+LHHqQWKvWojIwxMD4YQ1VNYJ2V+LG+hgH+B2vlrNowxGZsZlM34gkObf9qdec8 ustXl5GlfBfNUdLqDIj7IuLlXQB1fmBFvWZ69L3+5k4d+Uh0nYFFEkHhgBOeCAtZadAh YDjS5hZrESKmm7hxWkAwusWP1vUf31Hmn3FYxMsM6qYGW1+SjfuNDlzRIo8RcXG9o2qx tSuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=B4yWHzIV2L8DYHsuCwQr8Jl+t6iWEiT99YB+g+PxVJ0=; b=OPkcTGN5MsFjtauUi09sVW27jN6WgQUh+uATY5IOlst1OGza6Wy64cg8bgubzYvBpi Y+pk2vrvoHAzza3A/z6qFneXbRAzf6wCpw8smx/J+qLK6fuienr/HcrVzGaDcyZeWgB1 xHIrXavhRxW7opsyPEo4GR2zUUVHfXbrDlzIoGH7PpoF1rsb1ZTdIvo0GofHoSX2iz09 8vxQA9QeNHtmYIhNa1i2Rcy/gyJUegkoXjAwdbRzGHEohmehaj1Vb+b4Z3foosbdm1Xy R9Fmz3l2rHKj3rkUA+qq47Ks0WIp8rLJitFgEsnIQoN0HA2Pzy9vNsbetKJwoLhLvAEl Srxg== X-Gm-Message-State: APjAAAVBTHJICcvCd7B3h31aD+Nj2Jqmfd7XWqY5c3fYVh2gIvdAubXy leMlWu/Oditg/enJ8SQkKaikUsD606XuZH2zOl1XUw== X-Google-Smtp-Source: APXvYqwEaH4FBHYim7pgk+R5Iwed9VyMLH25KCU7dENXN+SBUFaYCAKLKWmdC4e7U/qAeMMI0Dc/WvpzBOJkvqdO5dTPTw== X-Received: by 2002:a05:620a:64c:: with SMTP id a12mr23678733qka.391.1566260365395; Mon, 19 Aug 2019 17:19:25 -0700 (PDT) Date: Mon, 19 Aug 2019 17:18:05 -0700 In-Reply-To: <20190820001805.241928-1-matthewgarrett@google.com> Message-Id: <20190820001805.241928-30-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190820001805.241928-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog Subject: [PATCH V40 29/29] lockdown: Print current->comm in restriction messages From: Matthew Garrett To: jmorris@namei.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Matthew Garrett , David Howells , Matthew Garrett , Kees Cook Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: Print the content of current->comm in messages generated by lockdown to indicate a restriction that was hit. This makes it a bit easier to find out what caused the message. The message now patterned something like: Lockdown: : is restricted; see man kernel_lockdown.7 Signed-off-by: David Howells Signed-off-by: Matthew Garrett Reviewed-by: Kees Cook Signed-off-by: James Morris --- fs/proc/kcore.c | 5 +++-- security/lockdown/lockdown.c | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index ee2c576cc94e..e2ed8e08cc7a 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -548,11 +548,12 @@ static int open_kcore(struct inode *inode, struct file *filp) { int ret = security_locked_down(LOCKDOWN_KCORE); - if (ret) - return ret; if (!capable(CAP_SYS_RAWIO)) return -EPERM; + if (ret) + return ret; + filp->private_data = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!filp->private_data) return -ENOMEM; diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c index 84df03b1f5a7..0068cec77c05 100644 --- a/security/lockdown/lockdown.c +++ b/security/lockdown/lockdown.c @@ -81,10 +81,14 @@ early_param("lockdown", lockdown_param); */ static int lockdown_is_locked_down(enum lockdown_reason what) { + if (WARN(what >= LOCKDOWN_CONFIDENTIALITY_MAX, + "Invalid lockdown reason")) + return -EPERM; + if (kernel_locked_down >= what) { if (lockdown_reasons[what]) - pr_notice("Lockdown: %s is restricted; see man kernel_lockdown.7\n", - lockdown_reasons[what]); + pr_notice("Lockdown: %s: %s is restricted; see man kernel_lockdown.7\n", + current->comm, lockdown_reasons[what]); return -EPERM; }