audit: Report suspicious O_CREAT usage
PATCH v2 1/1 audit: Report suspicious O_CREAT usage
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"). Additionally further clarifies the existing "operations" strings.
---
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(-)
fs/namei.c +6 -2
@@ -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 ,"sticky_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 ,"unowned_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 ;
include/linux/audit.h +3 -2
@@ -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) {
include/uapi/linux/audit.h +1 -0
@@ -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 */
kernel/audit.c +6 -5
@@ -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);
Signature · 5 lines
2.17.1 -- Kees Cook
Paul Moore
maintainerQuoted 14 lines · Kees Cook
This renames the very specific
audit_log_link_denied()toaudit_log_path_denied()and adds the AUDIT_* type as an argument. This allows for the creation of the newAUDIT_ANOM_CREATthat can be used to report the fifo/regular file creation restrictions that were introduced in commit30aba6656f61("namei: allow restrictedO_CREATof FIFOs and regular files"). Additionally further clarifies the existing "operations" strings.Signed-off-by Kees Cook <[email protected]>---
v2:
- fix build failure typo inCONFIG_AUDIT=ncase
- improve operations naming (paul)
Quoted 6 lines
--- 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(-)
Thanks for the update, but I think we need another respin, see below.
fs/namei.c static inline int may_follow_link(struct nameidata *nd) · line 928
Quoted 10 lines
fs/namei.c +1
-1@@ -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 ,"sticky_follow_link" );
Maybe I should have been more clear in the last patch thread, but my suggested name change was only for the new records you are adding; we don't want to change the operation/op names for existing records. In the above change, "follow_link" should stay "follow_link".
fs/namei.c static int may_linkat(struct path *link) · line 996
Quoted 6 lines
fs/namei.c +1
-1@@ -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 ,"unowned_linkat" );
See above, this should stay as "linkat".
fs/namei.c static int may_create_in_sticky(struct dentry * const dir, · line 1037
Quoted 8 lines
fs/namei.c +4
-0@@ -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);
This is a new record, so this is fine. Thanks for changing this.
Signature · 2 lines
paul moore www.paul-moore.com