@@ -32,6 +32,7 @@ static char *tomoyo_print_bprm(struct linux_binprm *bprm,
3232 int argv_count = bprm -> argc ;
3333 int envp_count = bprm -> envc ;
3434 bool truncated = false;
35+
3536 if (!buffer )
3637 return NULL ;
3738 len = snprintf (buffer , tomoyo_buffer_len - 1 , "argv[]={ " );
@@ -49,6 +50,7 @@ static char *tomoyo_print_bprm(struct linux_binprm *bprm,
4950 while (offset < PAGE_SIZE ) {
5051 const char * kaddr = dump -> data ;
5152 const unsigned char c = kaddr [offset ++ ];
53+
5254 if (cp == last_start )
5355 * cp ++ = '"' ;
5456 if (cp >= buffer + tomoyo_buffer_len - 32 ) {
@@ -154,19 +156,18 @@ static char *tomoyo_print_header(struct tomoyo_request_info *r)
154156 char * buffer = kmalloc (tomoyo_buffer_len , GFP_NOFS );
155157 int pos ;
156158 u8 i ;
159+
157160 if (!buffer )
158161 return NULL ;
159162
160163 tomoyo_convert_time (ktime_get_real_seconds (), & stamp );
161164
162165 pos = snprintf (buffer , tomoyo_buffer_len - 1 ,
163- "#%04u/%02u/%02u %02u:%02u:%02u# profile=%u mode=%s "
164- "granted=%s (global-pid=%u) task={ pid=%u ppid=%u "
165- "uid=%u gid=%u euid=%u egid=%u suid=%u sgid=%u "
166- "fsuid=%u fsgid=%u }" , stamp .year , stamp .month ,
167- stamp .day , stamp .hour , stamp .min , stamp .sec , r -> profile ,
168- tomoyo_mode [r -> mode ], tomoyo_yesno (r -> granted ), gpid ,
169- tomoyo_sys_getpid (), tomoyo_sys_getppid (),
166+ "#%04u/%02u/%02u %02u:%02u:%02u# profile=%u mode=%s granted=%s (global-pid=%u) task={ pid=%u ppid=%u uid=%u gid=%u euid=%u egid=%u suid=%u sgid=%u fsuid=%u fsgid=%u }" ,
167+ stamp .year , stamp .month , stamp .day , stamp .hour ,
168+ stamp .min , stamp .sec , r -> profile , tomoyo_mode [r -> mode ],
169+ tomoyo_yesno (r -> granted ), gpid , tomoyo_sys_getpid (),
170+ tomoyo_sys_getppid (),
170171 from_kuid (& init_user_ns , current_uid ()),
171172 from_kgid (& init_user_ns , current_gid ()),
172173 from_kuid (& init_user_ns , current_euid ()),
@@ -185,6 +186,7 @@ static char *tomoyo_print_header(struct tomoyo_request_info *r)
185186 struct tomoyo_mini_stat * stat ;
186187 unsigned int dev ;
187188 umode_t mode ;
189+
188190 if (!obj -> stat_valid [i ])
189191 continue ;
190192 stat = & obj -> stat [i ];
@@ -193,17 +195,17 @@ static char *tomoyo_print_header(struct tomoyo_request_info *r)
193195 if (i & 1 ) {
194196 pos += snprintf (buffer + pos ,
195197 tomoyo_buffer_len - 1 - pos ,
196- " path%u.parent={ uid=%u gid=%u "
197- "ino=%lu perm=0%o }" , (i >> 1 ) + 1 ,
198+ " path%u.parent={ uid=%u gid=%u ino=%lu perm=0%o }" ,
199+ (i >> 1 ) + 1 ,
198200 from_kuid (& init_user_ns , stat -> uid ),
199201 from_kgid (& init_user_ns , stat -> gid ),
200202 (unsigned long )stat -> ino ,
201203 stat -> mode & S_IALLUGO );
202204 continue ;
203205 }
204206 pos += snprintf (buffer + pos , tomoyo_buffer_len - 1 - pos ,
205- " path%u={ uid=%u gid=%u ino=%lu major=%u"
206- " minor=%u perm=0%o type=%s" , (i >> 1 ) + 1 ,
207+ " path%u={ uid=%u gid=%u ino=%lu major=%u minor=%u perm=0%o type=%s" ,
208+ (i >> 1 ) + 1 ,
207209 from_kuid (& init_user_ns , stat -> uid ),
208210 from_kgid (& init_user_ns , stat -> gid ),
209211 (unsigned long )stat -> ino ,
@@ -249,13 +251,15 @@ char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt,
249251 const char * symlink = NULL ;
250252 int pos ;
251253 const char * domainname = r -> domain -> domainname -> name ;
254+
252255 header = tomoyo_print_header (r );
253256 if (!header )
254257 return NULL ;
255258 /* +10 is for '\n' etc. and '\0'. */
256259 len += strlen (domainname ) + strlen (header ) + 10 ;
257260 if (r -> ee ) {
258261 struct file * file = r -> ee -> bprm -> file ;
262+
259263 realpath = tomoyo_realpath_from_path (& file -> f_path );
260264 bprm_info = tomoyo_print_bprm (r -> ee -> bprm , & r -> ee -> dump );
261265 if (!realpath || !bprm_info )
@@ -275,6 +279,7 @@ char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt,
275279 pos = snprintf (buf , len , "%s" , header );
276280 if (realpath ) {
277281 struct linux_binprm * bprm = r -> ee -> bprm ;
282+
278283 pos += snprintf (buf + pos , len - pos ,
279284 " exec={ realpath=\"%s\" argc=%d envc=%d %s }" ,
280285 realpath , bprm -> argc , bprm -> envc , bprm_info );
@@ -328,6 +333,7 @@ static bool tomoyo_get_audit(const struct tomoyo_policy_namespace *ns,
328333 const u8 category = tomoyo_index2category [index ] +
329334 TOMOYO_MAX_MAC_INDEX ;
330335 struct tomoyo_profile * p ;
336+
331337 if (!tomoyo_policy_loaded )
332338 return false;
333339 p = tomoyo_profile (ns , profile );
@@ -362,6 +368,7 @@ void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
362368 char * buf ;
363369 struct tomoyo_log * entry ;
364370 bool quota_exceeded = false;
371+
365372 if (!tomoyo_get_audit (r -> domain -> ns , r -> profile , r -> type ,
366373 r -> matched_acl , r -> granted ))
367374 goto out ;
@@ -413,6 +420,7 @@ void tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...)
413420{
414421 va_list args ;
415422 int len ;
423+
416424 va_start (args , fmt );
417425 len = vsnprintf ((char * ) & len , 1 , fmt , args ) + 1 ;
418426 va_end (args );
@@ -431,6 +439,7 @@ void tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...)
431439void tomoyo_read_log (struct tomoyo_io_buffer * head )
432440{
433441 struct tomoyo_log * ptr = NULL ;
442+
434443 if (head -> r .w_pos )
435444 return ;
436445 kfree (head -> read_buf );
0 commit comments