@@ -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+
11421168static 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+
12641381static 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