Skip to content

Commit 245d736

Browse files
keespcmoore
authored andcommitted
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 30aba66 ("namei: allow restricted O_CREAT of FIFOs and regular files"). Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 54ecb8f commit 245d736

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

fs/namei.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ static inline int may_follow_link(struct nameidata *nd)
925925
return -ECHILD;
926926

927927
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");
929929
return -EACCES;
930930
}
931931

@@ -993,7 +993,7 @@ static int may_linkat(struct path *link)
993993
if (safe_hardlink_source(inode) || inode_owner_or_capable(inode))
994994
return 0;
995995

996-
audit_log_link_denied("linkat");
996+
audit_log_path_denied(AUDIT_ANOM_LINK, "linkat");
997997
return -EPERM;
998998
}
999999

@@ -1031,6 +1031,10 @@ static int may_create_in_sticky(struct dentry * const dir,
10311031
(dir->d_inode->i_mode & 0020 &&
10321032
((sysctl_protected_fifos >= 2 && S_ISFIFO(inode->i_mode)) ||
10331033
(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);
10341038
return -EACCES;
10351039
}
10361040
return 0;

include/linux/audit.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ extern void audit_log_d_path(struct audit_buffer *ab,
156156
const struct path *path);
157157
extern void audit_log_key(struct audit_buffer *ab,
158158
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);
160161
extern void audit_log_lost(const char *message);
161162

162163
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,
217218
{ }
218219
static inline void audit_log_key(struct audit_buffer *ab, char *key)
219220
{ }
220-
static inline void audit_log_link_denied(const char *string)
221+
static inline void audit_log_path_denied(int type, const char *operation)
221222
{ }
222223
static inline int audit_log_task_context(struct audit_buffer *ab)
223224
{

include/uapi/linux/audit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
#define AUDIT_ANOM_PROMISCUOUS 1700 /* Device changed promiscuous mode */
144144
#define AUDIT_ANOM_ABEND 1701 /* Process ended abnormally */
145145
#define AUDIT_ANOM_LINK 1702 /* Suspicious use of file links */
146+
#define AUDIT_ANOM_CREAT 1703 /* Suspicious file creation */
146147
#define AUDIT_INTEGRITY_DATA 1800 /* Data integrity verification */
147148
#define AUDIT_INTEGRITY_METADATA 1801 /* Metadata integrity verification */
148149
#define AUDIT_INTEGRITY_STATUS 1802 /* Integrity enable status */

kernel/audit.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,18 +2155,19 @@ void audit_log_task_info(struct audit_buffer *ab)
21552155
EXPORT_SYMBOL(audit_log_task_info);
21562156

21572157
/**
2158-
* audit_log_link_denied - report a link restriction denial
2159-
* @operation: specific link operation
2158+
* audit_log_path_denied - report a path restriction denial
2159+
* @type: audit message type (AUDIT_ANOM_LINK, AUDIT_ANOM_CREAT, etc)
2160+
* @operation: specific operation name
21602161
*/
2161-
void audit_log_link_denied(const char *operation)
2162+
void audit_log_path_denied(int type, const char *operation)
21622163
{
21632164
struct audit_buffer *ab;
21642165

21652166
if (!audit_enabled || audit_dummy_context())
21662167
return;
21672168

2168-
/* Generate AUDIT_ANOM_LINK with subject, operation, outcome. */
2169-
ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_ANOM_LINK);
2169+
/* Generate log with subject, operation, outcome. */
2170+
ab = audit_log_start(audit_context(), GFP_KERNEL, type);
21702171
if (!ab)
21712172
return;
21722173
audit_log_format(ab, "op=%s", operation);

0 commit comments

Comments
 (0)