From patchwork Thu Jul 18 19:44:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 11049479 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41DBC138D for ; Thu, 18 Jul 2019 19:45:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E72827FA5 for ; Thu, 18 Jul 2019 19:45:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FAC52837D; Thu, 18 Jul 2019 19:45:42 +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=-14.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,USER_IN_DEF_DKIM_WL 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 BD2B727FA5 for ; Thu, 18 Jul 2019 19:45:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404140AbfGRTpk (ORCPT ); Thu, 18 Jul 2019 15:45:40 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:34608 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404141AbfGRTpe (ORCPT ); Thu, 18 Jul 2019 15:45:34 -0400 Received: by mail-pg1-f202.google.com with SMTP id x19so17257900pgx.1 for ; Thu, 18 Jul 2019 12:45:34 -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=hUShFVcCo5z4Vl3457oUOrEoTffedxXk2/9xvS7FuNM=; b=CJD3zXMJRh5tbW+A67mz1tOJy0iCefcuHuCF9CqC00ee5HPWJ+EPTRYHQ8ajqBaBpk On5yctHipOLwatF4emIFuwjwV4cAL/4CHJqeWsraFBTrkYS5b1MYzf8yGymfU0hD7iNY kW6VS8hGFeCkYQyskxGv+nFgLhidXD2Hu5eS9gqPw/vt5pzoyeIrOqfu3bgU3NyBcKIl zU+zCVGeTrV3lqhR4r4KmuJjkRO5PReh2YnByyV4Ds2akzBp83izrunExNbHqoSA9cQ8 O09OnKxXaQt5yUg5K/5hIhJVWUv3q7aUBmQg9Rb3d1QKzQuH31I3UY8gXT2lsOIsIEWu LzZA== 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=hUShFVcCo5z4Vl3457oUOrEoTffedxXk2/9xvS7FuNM=; b=cxN0jmYj1MzKxr+WFZ2Fxe6OOJR5i73lXpK55w0CYanGp0zNn4QDxz2C7H4CltxjHV DboslQT9jKejQ6vSVH/G8TWkuAxFiVQMCqNXDZ4zVsqfNbXwS1NTKNbUHX3oz2B2amE8 dDS9umAUKTMp1LuHr11bIGvzWeB0qZqH4PgwYUxVVT42xc8CmzN53Y0yn0U03FbJ6dyB 7ieTqOR7Lk4OkkeI42ua8NAG/xAfcRtvI1G45pU8yr6kZPek3bLpRfZWtYlfusImPD9l jsnwNHjPvfqtfUSDb/FHALU3psgNkb/82a1Gnn1WPlTa+eajuGtTbUKymuD2YOapO71d 3Skg== X-Gm-Message-State: APjAAAXG3bs7kEw+hJmYJLDzDLC47dj401AKVUlA2P7XJeT8duPKLycC mnCPAz2V7WNWHlxLhvVDUGBocYBJ4dT+hRXYk6jkQw== X-Google-Smtp-Source: APXvYqxRl0m6R5tyypODQDLX5ZwoNGI0xsocAUQ1JRoVVkexFRxjj6K1/Odu3+aEPQS9ZHP7Elcf+U+H3Mj9DB3einjMDw== X-Received: by 2002:a63:1310:: with SMTP id i16mr48823144pgl.187.1563479133401; Thu, 18 Jul 2019 12:45:33 -0700 (PDT) Date: Thu, 18 Jul 2019 12:44:15 -0700 In-Reply-To: <20190718194415.108476-1-matthewgarrett@google.com> Message-Id: <20190718194415.108476-30-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190718194415.108476-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH V36 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: X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 173191562047..f6c74cf6a798 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; }