Skip to content

Commit 5f3d544

Browse files
rgbriggspcmoore
authored andcommitted
audit: remove audit_context when CONFIG_ AUDIT and not AUDITSYSCALL
Remove audit_context from struct task_struct and struct audit_buffer when CONFIG_AUDIT is enabled but CONFIG_AUDITSYSCALL is not. Also, audit_log_name() (and supporting inode and fcaps functions) should have been put back in auditsc.c when soft and hard link logging was normalized since it is only used by syscall auditing. See github issue linux-audit/audit-kernel#105 Signed-off-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 90462a5 commit 5f3d544

4 files changed

Lines changed: 161 additions & 167 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,10 @@ struct task_struct {
885885

886886
struct callback_head *task_works;
887887

888-
struct audit_context *audit_context;
889888
#ifdef CONFIG_AUDIT
889+
#ifdef CONFIG_AUDITSYSCALL
890+
struct audit_context *audit_context;
891+
#endif
890892
kuid_t loginuid;
891893
unsigned int sessionid;
892894
#endif

‎kernel/audit.c‎

Lines changed: 0 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,163 +2067,6 @@ void audit_log_key(struct audit_buffer *ab, char *key)
20672067
audit_log_format(ab, "(null)");
20682068
}
20692069

2070-
void audit_log_cap(struct audit_buffer *ab, char *prefix, kernel_cap_t *cap)
2071-
{
2072-
int i;
2073-
2074-
if (cap_isclear(*cap)) {
2075-
audit_log_format(ab, " %s=0", prefix);
2076-
return;
2077-
}
2078-
audit_log_format(ab, " %s=", prefix);
2079-
CAP_FOR_EACH_U32(i)
2080-
audit_log_format(ab, "%08x", cap->cap[CAP_LAST_U32 - i]);
2081-
}
2082-
2083-
static void audit_log_fcaps(struct audit_buffer *ab, struct audit_names *name)
2084-
{
2085-
if (name->fcap_ver == -1) {
2086-
audit_log_format(ab, " cap_fe=? cap_fver=? cap_fp=? cap_fi=?");
2087-
return;
2088-
}
2089-
audit_log_cap(ab, "cap_fp", &name->fcap.permitted);
2090-
audit_log_cap(ab, "cap_fi", &name->fcap.inheritable);
2091-
audit_log_format(ab, " cap_fe=%d cap_fver=%x cap_frootid=%d",
2092-
name->fcap.fE, name->fcap_ver,
2093-
from_kuid(&init_user_ns, name->fcap.rootid));
2094-
}
2095-
2096-
static inline int audit_copy_fcaps(struct audit_names *name,
2097-
const struct dentry *dentry)
2098-
{
2099-
struct cpu_vfs_cap_data caps;
2100-
int rc;
2101-
2102-
if (!dentry)
2103-
return 0;
2104-
2105-
rc = get_vfs_caps_from_disk(dentry, &caps);
2106-
if (rc)
2107-
return rc;
2108-
2109-
name->fcap.permitted = caps.permitted;
2110-
name->fcap.inheritable = caps.inheritable;
2111-
name->fcap.fE = !!(caps.magic_etc & VFS_CAP_FLAGS_EFFECTIVE);
2112-
name->fcap.rootid = caps.rootid;
2113-
name->fcap_ver = (caps.magic_etc & VFS_CAP_REVISION_MASK) >>
2114-
VFS_CAP_REVISION_SHIFT;
2115-
2116-
return 0;
2117-
}
2118-
2119-
/* Copy inode data into an audit_names. */
2120-
void audit_copy_inode(struct audit_names *name, const struct dentry *dentry,
2121-
struct inode *inode, unsigned int flags)
2122-
{
2123-
name->ino = inode->i_ino;
2124-
name->dev = inode->i_sb->s_dev;
2125-
name->mode = inode->i_mode;
2126-
name->uid = inode->i_uid;
2127-
name->gid = inode->i_gid;
2128-
name->rdev = inode->i_rdev;
2129-
security_inode_getsecid(inode, &name->osid);
2130-
if (flags & AUDIT_INODE_NOEVAL) {
2131-
name->fcap_ver = -1;
2132-
return;
2133-
}
2134-
audit_copy_fcaps(name, dentry);
2135-
}
2136-
2137-
/**
2138-
* audit_log_name - produce AUDIT_PATH record from struct audit_names
2139-
* @context: audit_context for the task
2140-
* @n: audit_names structure with reportable details
2141-
* @path: optional path to report instead of audit_names->name
2142-
* @record_num: record number to report when handling a list of names
2143-
* @call_panic: optional pointer to int that will be updated if secid fails
2144-
*/
2145-
void audit_log_name(struct audit_context *context, struct audit_names *n,
2146-
const struct path *path, int record_num, int *call_panic)
2147-
{
2148-
struct audit_buffer *ab;
2149-
ab = audit_log_start(context, GFP_KERNEL, AUDIT_PATH);
2150-
if (!ab)
2151-
return;
2152-
2153-
audit_log_format(ab, "item=%d", record_num);
2154-
2155-
if (path)
2156-
audit_log_d_path(ab, " name=", path);
2157-
else if (n->name) {
2158-
switch (n->name_len) {
2159-
case AUDIT_NAME_FULL:
2160-
/* log the full path */
2161-
audit_log_format(ab, " name=");
2162-
audit_log_untrustedstring(ab, n->name->name);
2163-
break;
2164-
case 0:
2165-
/* name was specified as a relative path and the
2166-
* directory component is the cwd */
2167-
audit_log_d_path(ab, " name=", &context->pwd);
2168-
break;
2169-
default:
2170-
/* log the name's directory component */
2171-
audit_log_format(ab, " name=");
2172-
audit_log_n_untrustedstring(ab, n->name->name,
2173-
n->name_len);
2174-
}
2175-
} else
2176-
audit_log_format(ab, " name=(null)");
2177-
2178-
if (n->ino != AUDIT_INO_UNSET)
2179-
audit_log_format(ab, " inode=%lu"
2180-
" dev=%02x:%02x mode=%#ho"
2181-
" ouid=%u ogid=%u rdev=%02x:%02x",
2182-
n->ino,
2183-
MAJOR(n->dev),
2184-
MINOR(n->dev),
2185-
n->mode,
2186-
from_kuid(&init_user_ns, n->uid),
2187-
from_kgid(&init_user_ns, n->gid),
2188-
MAJOR(n->rdev),
2189-
MINOR(n->rdev));
2190-
if (n->osid != 0) {
2191-
char *ctx = NULL;
2192-
u32 len;
2193-
if (security_secid_to_secctx(
2194-
n->osid, &ctx, &len)) {
2195-
audit_log_format(ab, " osid=%u", n->osid);
2196-
if (call_panic)
2197-
*call_panic = 2;
2198-
} else {
2199-
audit_log_format(ab, " obj=%s", ctx);
2200-
security_release_secctx(ctx, len);
2201-
}
2202-
}
2203-
2204-
/* log the audit_names record type */
2205-
switch(n->type) {
2206-
case AUDIT_TYPE_NORMAL:
2207-
audit_log_format(ab, " nametype=NORMAL");
2208-
break;
2209-
case AUDIT_TYPE_PARENT:
2210-
audit_log_format(ab, " nametype=PARENT");
2211-
break;
2212-
case AUDIT_TYPE_CHILD_DELETE:
2213-
audit_log_format(ab, " nametype=DELETE");
2214-
break;
2215-
case AUDIT_TYPE_CHILD_CREATE:
2216-
audit_log_format(ab, " nametype=CREATE");
2217-
break;
2218-
default:
2219-
audit_log_format(ab, " nametype=UNKNOWN");
2220-
break;
2221-
}
2222-
2223-
audit_log_fcaps(ab, n);
2224-
audit_log_end(ab);
2225-
}
2226-
22272070
int audit_log_task_context(struct audit_buffer *ab)
22282071
{
22292072
char *ctx = NULL;

‎kernel/audit.h‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,6 @@ extern bool audit_ever_enabled;
213213

214214
extern void audit_log_session_info(struct audit_buffer *ab);
215215

216-
extern void audit_copy_inode(struct audit_names *name,
217-
const struct dentry *dentry,
218-
struct inode *inode, unsigned int flags);
219-
extern void audit_log_cap(struct audit_buffer *ab, char *prefix,
220-
kernel_cap_t *cap);
221-
extern void audit_log_name(struct audit_context *context,
222-
struct audit_names *n, const struct path *path,
223-
int record_num, int *call_panic);
224-
225216
extern int auditd_test_task(struct task_struct *task);
226217

227218
#define AUDIT_INODE_BUCKETS 32

‎kernel/auditsc.c‎

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,32 @@ static void audit_log_execve_info(struct audit_context *context,
11391139
kfree(buf_head);
11401140
}
11411141

1142+
void audit_log_cap(struct audit_buffer *ab, char *prefix, kernel_cap_t *cap)
1143+
{
1144+
int i;
1145+
1146+
if (cap_isclear(*cap)) {
1147+
audit_log_format(ab, " %s=0", prefix);
1148+
return;
1149+
}
1150+
audit_log_format(ab, " %s=", prefix);
1151+
CAP_FOR_EACH_U32(i)
1152+
audit_log_format(ab, "%08x", cap->cap[CAP_LAST_U32 - i]);
1153+
}
1154+
1155+
static void audit_log_fcaps(struct audit_buffer *ab, struct audit_names *name)
1156+
{
1157+
if (name->fcap_ver == -1) {
1158+
audit_log_format(ab, " cap_fe=? cap_fver=? cap_fp=? cap_fi=?");
1159+
return;
1160+
}
1161+
audit_log_cap(ab, "cap_fp", &name->fcap.permitted);
1162+
audit_log_cap(ab, "cap_fi", &name->fcap.inheritable);
1163+
audit_log_format(ab, " cap_fe=%d cap_fver=%x cap_frootid=%d",
1164+
name->fcap.fE, name->fcap_ver,
1165+
from_kuid(&init_user_ns, name->fcap.rootid));
1166+
}
1167+
11421168
static void show_special(struct audit_context *context, int *call_panic)
11431169
{
11441170
struct audit_buffer *ab;
@@ -1261,6 +1287,97 @@ static inline int audit_proctitle_rtrim(char *proctitle, int len)
12611287
return len;
12621288
}
12631289

1290+
/*
1291+
* audit_log_name - produce AUDIT_PATH record from struct audit_names
1292+
* @context: audit_context for the task
1293+
* @n: audit_names structure with reportable details
1294+
* @path: optional path to report instead of audit_names->name
1295+
* @record_num: record number to report when handling a list of names
1296+
* @call_panic: optional pointer to int that will be updated if secid fails
1297+
*/
1298+
static void audit_log_name(struct audit_context *context, struct audit_names *n,
1299+
const struct path *path, int record_num, int *call_panic)
1300+
{
1301+
struct audit_buffer *ab;
1302+
1303+
ab = audit_log_start(context, GFP_KERNEL, AUDIT_PATH);
1304+
if (!ab)
1305+
return;
1306+
1307+
audit_log_format(ab, "item=%d", record_num);
1308+
1309+
if (path)
1310+
audit_log_d_path(ab, " name=", path);
1311+
else if (n->name) {
1312+
switch (n->name_len) {
1313+
case AUDIT_NAME_FULL:
1314+
/* log the full path */
1315+
audit_log_format(ab, " name=");
1316+
audit_log_untrustedstring(ab, n->name->name);
1317+
break;
1318+
case 0:
1319+
/* name was specified as a relative path and the
1320+
* directory component is the cwd
1321+
*/
1322+
audit_log_d_path(ab, " name=", &context->pwd);
1323+
break;
1324+
default:
1325+
/* log the name's directory component */
1326+
audit_log_format(ab, " name=");
1327+
audit_log_n_untrustedstring(ab, n->name->name,
1328+
n->name_len);
1329+
}
1330+
} else
1331+
audit_log_format(ab, " name=(null)");
1332+
1333+
if (n->ino != AUDIT_INO_UNSET)
1334+
audit_log_format(ab, " inode=%lu dev=%02x:%02x mode=%#ho ouid=%u ogid=%u rdev=%02x:%02x",
1335+
n->ino,
1336+
MAJOR(n->dev),
1337+
MINOR(n->dev),
1338+
n->mode,
1339+
from_kuid(&init_user_ns, n->uid),
1340+
from_kgid(&init_user_ns, n->gid),
1341+
MAJOR(n->rdev),
1342+
MINOR(n->rdev));
1343+
if (n->osid != 0) {
1344+
char *ctx = NULL;
1345+
u32 len;
1346+
1347+
if (security_secid_to_secctx(
1348+
n->osid, &ctx, &len)) {
1349+
audit_log_format(ab, " osid=%u", n->osid);
1350+
if (call_panic)
1351+
*call_panic = 2;
1352+
} else {
1353+
audit_log_format(ab, " obj=%s", ctx);
1354+
security_release_secctx(ctx, len);
1355+
}
1356+
}
1357+
1358+
/* log the audit_names record type */
1359+
switch (n->type) {
1360+
case AUDIT_TYPE_NORMAL:
1361+
audit_log_format(ab, " nametype=NORMAL");
1362+
break;
1363+
case AUDIT_TYPE_PARENT:
1364+
audit_log_format(ab, " nametype=PARENT");
1365+
break;
1366+
case AUDIT_TYPE_CHILD_DELETE:
1367+
audit_log_format(ab, " nametype=DELETE");
1368+
break;
1369+
case AUDIT_TYPE_CHILD_CREATE:
1370+
audit_log_format(ab, " nametype=CREATE");
1371+
break;
1372+
default:
1373+
audit_log_format(ab, " nametype=UNKNOWN");
1374+
break;
1375+
}
1376+
1377+
audit_log_fcaps(ab, n);
1378+
audit_log_end(ab);
1379+
}
1380+
12641381
static void audit_log_proctitle(void)
12651382
{
12661383
int res;
@@ -1756,6 +1873,47 @@ void __audit_getname(struct filename *name)
17561873
get_fs_pwd(current->fs, &context->pwd);
17571874
}
17581875

1876+
static inline int audit_copy_fcaps(struct audit_names *name,
1877+
const struct dentry *dentry)
1878+
{
1879+
struct cpu_vfs_cap_data caps;
1880+
int rc;
1881+
1882+
if (!dentry)
1883+
return 0;
1884+
1885+
rc = get_vfs_caps_from_disk(dentry, &caps);
1886+
if (rc)
1887+
return rc;
1888+
1889+
name->fcap.permitted = caps.permitted;
1890+
name->fcap.inheritable = caps.inheritable;
1891+
name->fcap.fE = !!(caps.magic_etc & VFS_CAP_FLAGS_EFFECTIVE);
1892+
name->fcap.rootid = caps.rootid;
1893+
name->fcap_ver = (caps.magic_etc & VFS_CAP_REVISION_MASK) >>
1894+
VFS_CAP_REVISION_SHIFT;
1895+
1896+
return 0;
1897+
}
1898+
1899+
/* Copy inode data into an audit_names. */
1900+
void audit_copy_inode(struct audit_names *name, const struct dentry *dentry,
1901+
struct inode *inode, unsigned int flags)
1902+
{
1903+
name->ino = inode->i_ino;
1904+
name->dev = inode->i_sb->s_dev;
1905+
name->mode = inode->i_mode;
1906+
name->uid = inode->i_uid;
1907+
name->gid = inode->i_gid;
1908+
name->rdev = inode->i_rdev;
1909+
security_inode_getsecid(inode, &name->osid);
1910+
if (flags & AUDIT_INODE_NOEVAL) {
1911+
name->fcap_ver = -1;
1912+
return;
1913+
}
1914+
audit_copy_fcaps(name, dentry);
1915+
}
1916+
17591917
/**
17601918
* __audit_inode - store the inode and device from a lookup
17611919
* @name: name being audited

0 commit comments

Comments
 (0)