@@ -19,7 +19,9 @@ mod console;
1919mod types;
2020
2121use crate :: capability:: { KernelAuthority , KernelCapability , KernelObjectRef } ;
22+ use alloc:: format;
2223use alloc:: string:: String ;
24+ use alloc:: string:: ToString ;
2325use alloc:: vec:: Vec ;
2426use x86_64:: instructions:: port:: Port ;
2527
@@ -93,6 +95,11 @@ fn is_canonical_user_range(addr: u64, len: u64) -> bool {
9395 end_inclusive <= USER_SPACE_END
9496}
9597
98+ fn current_process_name_for_log ( ) -> Option < String > {
99+ let pid = crate :: syscall:: security:: current_process_id ( ) ?;
100+ crate :: task:: with_process ( pid, |p| p. name ( ) . to_string ( ) )
101+ }
102+
96103/// ユーザー空間の null 終端文字列を最大長付きで読み取り、カーネル所有の `String` を返す。
97104pub fn read_user_cstring ( ptr : u64 , max_len : usize ) -> Result < String , u64 > {
98105 if ptr == 0 || max_len == 0 {
@@ -345,9 +352,26 @@ pub fn copy_from_user(src_ptr: u64, dst: &mut [u8]) -> Result<(), u64> {
345352 return Err ( EFAULT ) ;
346353 }
347354 crate :: mem:: paging:: copy_from_user_in_table ( user_pt, src_ptr, dst) . map_err ( |err| {
355+ let ( syscall_num, syscall_args) = last_syscall_snapshot ( ) ;
356+ let pid = crate :: syscall:: security:: current_process_id ( )
357+ . map ( |pid| pid. as_u64 ( ) )
358+ . unwrap_or ( 0 ) ;
359+ let process_name = current_process_name_for_log ( ) . unwrap_or_else ( || "?" . to_string ( ) ) ;
348360 crate :: audit:: log (
349361 crate :: audit:: AuditEventKind :: Usercopy ,
350- "copy_from_user rejected unmapped or unreadable range" ,
362+ & format ! (
363+ "copy_from_user rejected unmapped or unreadable range pid={} process={} src={:#x} len={} last_syscall={} args=[{:#x},{:#x},{:#x},{:#x},{:#x}]" ,
364+ pid,
365+ process_name,
366+ src_ptr,
367+ dst. len( ) ,
368+ syscall_num,
369+ syscall_args[ 0 ] ,
370+ syscall_args[ 1 ] ,
371+ syscall_args[ 2 ] ,
372+ syscall_args[ 3 ] ,
373+ syscall_args[ 4 ]
374+ ) ,
351375 ) ;
352376 match err {
353377 crate :: Kernel :: Memory ( crate :: result:: Memory :: OutOfMemory ) => EFAULT ,
@@ -371,9 +395,26 @@ pub fn copy_to_user(dst_ptr: u64, src: &[u8]) -> Result<(), u64> {
371395 return Err ( EFAULT ) ;
372396 }
373397 crate :: mem:: paging:: copy_to_user_in_table ( user_pt, dst_ptr, src) . map_err ( |err| {
398+ let ( syscall_num, syscall_args) = last_syscall_snapshot ( ) ;
399+ let pid = crate :: syscall:: security:: current_process_id ( )
400+ . map ( |pid| pid. as_u64 ( ) )
401+ . unwrap_or ( 0 ) ;
402+ let process_name = current_process_name_for_log ( ) . unwrap_or_else ( || "?" . to_string ( ) ) ;
374403 crate :: audit:: log (
375404 crate :: audit:: AuditEventKind :: Usercopy ,
376- "copy_to_user rejected unmapped or unwritable range" ,
405+ & format ! (
406+ "copy_to_user rejected unmapped or unwritable range pid={} process={} dst={:#x} len={} last_syscall={} args=[{:#x},{:#x},{:#x},{:#x},{:#x}]" ,
407+ pid,
408+ process_name,
409+ dst_ptr,
410+ src. len( ) ,
411+ syscall_num,
412+ syscall_args[ 0 ] ,
413+ syscall_args[ 1 ] ,
414+ syscall_args[ 2 ] ,
415+ syscall_args[ 3 ] ,
416+ syscall_args[ 4 ]
417+ ) ,
377418 ) ;
378419 match err {
379420 crate :: Kernel :: Memory ( crate :: result:: Memory :: OutOfMemory ) => EFAULT ,
0 commit comments