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").
Unified · Split
| @@ -925,7 +925,7 @@ static inline int may_follow_link(struct nameidata *nd) · 924 unmodified lines | |||
| 925 | return -ECHILD; | 925 | return -ECHILD; |
| 926 | 926 | ||
| 927 | audit_inode(nd->name, nd->stack[0].link.dentry, 0); | 927 | audit_inode(nd->name, nd->stack[0].link.dentry, 0); |
| 928 | audit_log_link_denied("follow_link"); | 928 | audit_log_path_denied(AUDIT_ANOM_LINK, "follow_link"); |
| 929 | return -EACCES; | 929 | return -EACCES; |
| 930 | } | 930 | } |
| 931 | 931 | ||
| @@ -993,7 +993,7 @@ static int may_linkat(struct path *link) · 61 unmodified lines | |||
| 993 | if (safe_hardlink_source(inode) || inode_owner_or_capable(inode)) | 993 | if (safe_hardlink_source(inode) || inode_owner_or_capable(inode)) |
| 994 | return 0; | 994 | return 0; |
| 995 | 995 | ||
| 996 | audit_log_link_denied("linkat"); | 996 | audit_log_path_denied(AUDIT_ANOM_LINK, "linkat"); |
| 997 | return -EPERM; | 997 | return -EPERM; |
| 998 | } | 998 | } |
| 999 | 999 | ||
| @@ -1031,6 +1031,10 @@ static int may_create_in_sticky(struct dentry * const dir, · 31 unmodified lines | |||
| 1031 | (dir->d_inode->i_mode & 0020 && | 1031 | (dir->d_inode->i_mode & 0020 && |
| 1032 | ((sysctl_protected_fifos >= 2 && S_ISFIFO(inode->i_mode)) || | 1032 | ((sysctl_protected_fifos >= 2 && S_ISFIFO(inode->i_mode)) || |
| 1033 | (sysctl_protected_regular >= 2 && S_ISREG(inode->i_mode))))) { | 1033 | (sysctl_protected_regular >= 2 && S_ISREG(inode->i_mode))))) { |
| 1034 | const char *operation = S_ISFIFO(inode->i_mode) ? | ||
| 1035 | "sticky_create_fifo" : | ||
| 1036 | "sticky_create_regular"; | ||
| 1037 | audit_log_path_denied(AUDIT_ANOM_CREAT, operation); | ||
| 1034 | return -EACCES; | 1038 | return -EACCES; |
| 1035 | } | 1039 | } |
| 1036 | return 0; | 1040 | return 0; |
| @@ -156,7 +156,8 @@ extern void audit_log_d_path(struct audit_buffer *ab, · 155 unmodified lines | |||
| 156 | const struct path *path); | 156 | const struct path *path); |
| 157 | extern void audit_log_key(struct audit_buffer *ab, | 157 | extern void audit_log_key(struct audit_buffer *ab, |
| 158 | char *key); | 158 | char *key); |
| 159 | extern void audit_log_link_denied(const char *operation); | 159 | extern void audit_log_path_denied(int type, |
| 160 | const char *operation); | ||
| 160 | extern void audit_log_lost(const char *message); | 161 | extern void audit_log_lost(const char *message); |
| 161 | 162 | ||
| 162 | extern int audit_log_task_context(struct audit_buffer *ab); | 163 | 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, · 54 unmodified lines | |||
| 217 | { } | 218 | { } |
| 218 | static inline void audit_log_key(struct audit_buffer *ab, char *key) | 219 | static inline void audit_log_key(struct audit_buffer *ab, char *key) |
| 219 | { } | 220 | { } |
| 220 | static inline void audit_log_link_denied(const char *string) | 221 | static inline void audit_log_path_denied(int type, const char *operation) |
| 221 | { } | 222 | { } |
| 222 | static inline int audit_log_task_context(struct audit_buffer *ab) | 223 | static inline int audit_log_task_context(struct audit_buffer *ab) |
| 223 | { | 224 | { |
| @@ -143,6 +143,7 @@ · 142 unmodified lines | |||
| 143 | #define AUDIT_ANOM_PROMISCUOUS 1700 /* Device changed promiscuous mode */ | 143 | #define AUDIT_ANOM_PROMISCUOUS 1700 /* Device changed promiscuous mode */ |
| 144 | #define AUDIT_ANOM_ABEND 1701 /* Process ended abnormally */ | 144 | #define AUDIT_ANOM_ABEND 1701 /* Process ended abnormally */ |
| 145 | #define AUDIT_ANOM_LINK 1702 /* Suspicious use of file links */ | 145 | #define AUDIT_ANOM_LINK 1702 /* Suspicious use of file links */ |
| 146 | #define AUDIT_ANOM_CREAT 1703 /* Suspicious file creation */ | ||
| 146 | #define AUDIT_INTEGRITY_DATA 1800 /* Data integrity verification */ | 147 | #define AUDIT_INTEGRITY_DATA 1800 /* Data integrity verification */ |
| 147 | #define AUDIT_INTEGRITY_METADATA 1801 /* Metadata integrity verification */ | 148 | #define AUDIT_INTEGRITY_METADATA 1801 /* Metadata integrity verification */ |
| 148 | #define AUDIT_INTEGRITY_STATUS 1802 /* Integrity enable status */ | 149 | #define AUDIT_INTEGRITY_STATUS 1802 /* Integrity enable status */ |
| @@ -2155,18 +2155,19 @@ void audit_log_task_info(struct audit_buffer *ab) · 2154 unmodified lines | |||
| 2155 | EXPORT_SYMBOL(audit_log_task_info); | 2155 | EXPORT_SYMBOL(audit_log_task_info); |
| 2156 | 2156 | ||
| 2157 | /** | 2157 | /** |
| 2158 | * audit_log_link_denied - report a link restriction denial | 2158 | * audit_log_path_denied - report a path restriction denial |
| 2159 | * @operation: specific link operation | 2159 | * @type: audit message type (AUDIT_ANOM_LINK, AUDIT_ANOM_CREAT, etc) |
| 2160 | * @operation: specific operation name | ||
| 2160 | */ | 2161 | */ |
| 2161 | void audit_log_link_denied(const char *operation) | 2162 | void audit_log_path_denied(int type, const char *operation) |
| 2162 | { | 2163 | { |
| 2163 | struct audit_buffer *ab; | 2164 | struct audit_buffer *ab; |
| 2164 | 2165 | ||
| 2165 | if (!audit_enabled || audit_dummy_context()) | 2166 | if (!audit_enabled || audit_dummy_context()) |
| 2166 | return; | 2167 | return; |
| 2167 | 2168 | ||
| 2168 | /* Generate AUDIT_ANOM_LINK with subject, operation, outcome. */ | 2169 | /* Generate log with subject, operation, outcome. */ |
| 2169 | ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_ANOM_LINK); | 2170 | ab = audit_log_start(audit_context(), GFP_KERNEL, type); |
| 2170 | if (!ab) | 2171 | if (!ab) |
| 2171 | return; | 2172 | return; |
| 2172 | audit_log_format(ab, "op=%s", operation); | 2173 | audit_log_format(ab, "op=%s", operation); |