From patchwork Wed Oct 2 23:41:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11171909 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 7B4401709 for ; Wed, 2 Oct 2019 23:42:16 +0000 (UTC) Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.kernel.org (Postfix) with SMTP id 3B20D21848 for ; Wed, 2 Oct 2019 23:42:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="RuaAqYMG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B20D21848 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernel-hardening-return-16985-patchwork-kernel-hardening=patchwork.kernel.org@lists.openwall.com Received: (qmail 5753 invoked by uid 550); 2 Oct 2019 23:42:13 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 5735 invoked from network); 2 Oct 2019 23:42:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=NTX0hkNxI05pnkppFwzWTqjYZZHE2LejCZuC9WmiKB0=; b=RuaAqYMGq6ZNHIeNyfRBleyOdT3qbOpk/MH7msZ+uzQd4zfMjwSbeKowJyaVBIXvZU e3ehgl3JtM8H8MCAj5clnFljDK9COp0ujetbeasrlPkVSPNRS9hKxxJVQzw8Jh+h4XJl N4i1UMuHVi6KLKg6ETIRJiderlGsTRvCULbMc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=NTX0hkNxI05pnkppFwzWTqjYZZHE2LejCZuC9WmiKB0=; b=WTKPzt4iwN5eIrzwLtiagCo2+vuUf6N9de7AzatBeMa96ss2TxZlyNzEvde2j5J61k sa2/5Bp27yMwZR4evImbT4N+DeAYjCEHcMp/J8pB/YaSaxHDGgQ3YjJgrxvb1YQCVUTv 8RFYwN7QZFLJrYpSCIStqaE+8NhuLemsBZRDBL0X5EcMvbtxunpAqIkFljhNENQ+1hfi w36LgT/MVwRKVlFzqSuLPcldsvVw5FRyBkd8U0PDmxAEqz/nkSa8xPebVy9Y9B16F/G8 IwfDqZ0yuveN3cRIju7/aWBAUoFj1PW5I4qehV7WP96jghB5B9g9Ci2QLNrnurIYEvzM 9NtQ== X-Gm-Message-State: APjAAAU30TfjxkHTBGmv4ry8PSC7rvEGwo+ijM8ml/DSDsep9GSKD+n1 2wSUmL3Ja5nx8UaVFyvIA0C+xA== X-Google-Smtp-Source: APXvYqy10qOgEi5CzIB/8gJv+NIva4xGBBOMqbDLDaqcYRruLZ/BQ1X8YbXNB1TkhaEHhOVlG+SuEg== X-Received: by 2002:a17:902:7782:: with SMTP id o2mr6111131pll.165.1570059720606; Wed, 02 Oct 2019 16:42:00 -0700 (PDT) Date: Wed, 2 Oct 2019 16:41:58 -0700 From: Kees Cook To: Paul Moore Cc: linux-kernel@vger.kernel.org, =?iso-8859-1?q?J=E9r=E9mie?= Galarneau , s.mesoraca16@gmail.com, viro@zeniv.linux.org.uk, dan.carpenter@oracle.com, akpm@linux-foundation.org, Mathieu Desnoyers , kernel-hardening@lists.openwall.com, linux-audit@redhat.com, Linus Torvalds Subject: [PATCH v3] audit: Report suspicious O_CREAT usage Message-ID: <201910021640.B01FA41@keescook> MIME-Version: 1.0 Content-Disposition: inline This renames the very specific audit_log_link_denied() to audit_log_path_denied() and adds the AUDIT_* type as an argument. This allows for the creation of the new AUDIT_ANOM_CREAT that can be used to report the fifo/regular file creation restrictions that were introduced in commit 30aba6656f61 ("namei: allow restricted O_CREAT of FIFOs and regular files"). Signed-off-by: Kees Cook --- v3: - retain existing operation names (paul) v2: - fix build failure typo in CONFIG_AUDIT=n case - improve operations naming (paul) --- fs/namei.c | 8 ++++++-- include/linux/audit.h | 5 +++-- include/uapi/linux/audit.h | 1 + kernel/audit.c | 11 ++++++----- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 671c3c1a3425..2dda552bcf7a 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -925,7 +925,7 @@ static inline int may_follow_link(struct nameidata *nd) return -ECHILD; audit_inode(nd->name, nd->stack[0].link.dentry, 0); - audit_log_link_denied("follow_link"); + audit_log_path_denied(AUDIT_ANOM_LINK, "follow_link"); return -EACCES; } @@ -993,7 +993,7 @@ static int may_linkat(struct path *link) if (safe_hardlink_source(inode) || inode_owner_or_capable(inode)) return 0; - audit_log_link_denied("linkat"); + audit_log_path_denied(AUDIT_ANOM_LINK, "linkat"); return -EPERM; } @@ -1031,6 +1031,10 @@ static int may_create_in_sticky(struct dentry * const dir, (dir->d_inode->i_mode & 0020 && ((sysctl_protected_fifos >= 2 && S_ISFIFO(inode->i_mode)) || (sysctl_protected_regular >= 2 && S_ISREG(inode->i_mode))))) { + const char *operation = S_ISFIFO(inode->i_mode) ? + "sticky_create_fifo" : + "sticky_create_regular"; + audit_log_path_denied(AUDIT_ANOM_CREAT, operation); return -EACCES; } return 0; diff --git a/include/linux/audit.h b/include/linux/audit.h index aee3dc9eb378..f9ceae57ca8d 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h @@ -156,7 +156,8 @@ extern void audit_log_d_path(struct audit_buffer *ab, const struct path *path); extern void audit_log_key(struct audit_buffer *ab, char *key); -extern void audit_log_link_denied(const char *operation); +extern void audit_log_path_denied(int type, + const char *operation); extern void audit_log_lost(const char *message); extern int audit_log_task_context(struct audit_buffer *ab); @@ -217,7 +218,7 @@ static inline void audit_log_d_path(struct audit_buffer *ab, { } static inline void audit_log_key(struct audit_buffer *ab, char *key) { } -static inline void audit_log_link_denied(const char *string) +static inline void audit_log_path_denied(int type, const char *operation) { } static inline int audit_log_task_context(struct audit_buffer *ab) { diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index c89c6495983d..3ad935527177 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -143,6 +143,7 @@ #define AUDIT_ANOM_PROMISCUOUS 1700 /* Device changed promiscuous mode */ #define AUDIT_ANOM_ABEND 1701 /* Process ended abnormally */ #define AUDIT_ANOM_LINK 1702 /* Suspicious use of file links */ +#define AUDIT_ANOM_CREAT 1703 /* Suspicious file creation */ #define AUDIT_INTEGRITY_DATA 1800 /* Data integrity verification */ #define AUDIT_INTEGRITY_METADATA 1801 /* Metadata integrity verification */ #define AUDIT_INTEGRITY_STATUS 1802 /* Integrity enable status */ diff --git a/kernel/audit.c b/kernel/audit.c index da8dc0db5bd3..d75485aa25ff 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -2155,18 +2155,19 @@ void audit_log_task_info(struct audit_buffer *ab) EXPORT_SYMBOL(audit_log_task_info); /** - * audit_log_link_denied - report a link restriction denial - * @operation: specific link operation + * audit_log_path_denied - report a path restriction denial + * @type: audit message type (AUDIT_ANOM_LINK, AUDIT_ANOM_CREAT, etc) + * @operation: specific operation name */ -void audit_log_link_denied(const char *operation) +void audit_log_path_denied(int type, const char *operation) { struct audit_buffer *ab; if (!audit_enabled || audit_dummy_context()) return; - /* Generate AUDIT_ANOM_LINK with subject, operation, outcome. */ - ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_ANOM_LINK); + /* Generate log with subject, operation, outcome. */ + ab = audit_log_start(audit_context(), GFP_KERNEL, type); if (!ab) return; audit_log_format(ab, "op=%s", operation);