Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:lib\test_user_copy.c Create Date:2022-07-28 06:32:03
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:test_user_copy_init

Proto:static int __init test_user_copy_init(void)

Type:int

Parameter:Nothing

182  ret = 0
184  __user * usermem
194  kmem = kmalloc(PAGE_SIZE * 2, GFP_KERNEL)
195  If Not kmem Then Return -ENOMEM
198  user_addr = vm_mmap(NULL, 0, PAGE_SIZE * 2, page can be read | page can be written | page can be executed , don't use a file | Changes are private , 0)
201  If user_addr >= TASK_SIZE Then
202  pr_warn("Failed to allocate user memory\n")
203  kfree(kmem)
204  Return -ENOMEM
207  usermem = user_addr
208  bad_usermem = user_addr
213  memset(kmem, 0x3a, PAGE_SIZE * 2)
214  ret |= test(copy_to_user(usermem, kmem, PAGE_SIZE), "legitimate copy_to_user failed")
216  memset(kmem, 0x0, PAGE_SIZE)
217  ret |= test(copy_from_user(kmem, usermem, PAGE_SIZE), "legitimate copy_from_user failed")
219  ret |= test(memcmp(kmem, kmem + PAGE_SIZE, PAGE_SIZE), "legitimate usercopy failed to copy data")
239  Legitimate usage: none of these copies should fail.(u8, 0x5a)
240  Legitimate usage: none of these copies should fail.(u16, 0x5a5b)
241  Legitimate usage: none of these copies should fail.(u32, 0x5a5b5c5d)
243  Legitimate usage: none of these copies should fail.(u64, 0x5a5b5c5d6a6b6c6d)
248  ret |= test_check_nonzero_user(kmem, usermem, 2 * PAGE_SIZE)
250  ret |= test_copy_struct_from_user(kmem, usermem, 2 * PAGE_SIZE)
257  memset(kmem, 0x5a, PAGE_SIZE)
258  memset(kmem + PAGE_SIZE, 0, PAGE_SIZE)
261  ret |= test(!copy_from_user(kmem, (char__user * )(kmem + PAGE_SIZE), PAGE_SIZE), "illegal all-kernel copy_from_user passed")
266  ret |= test(memcmp(kmem + PAGE_SIZE, kmem, PAGE_SIZE), "zeroing failure for illegal all-kernel copy_from_user")
280  ret |= test(!copy_to_user((char__user * )kmem, kmem + PAGE_SIZE, PAGE_SIZE), "illegal all-kernel copy_to_user passed")
283  ret |= test(!copy_to_user((char__user * )kmem, bad_usermem, PAGE_SIZE), "illegal reversed copy_to_user passed")
302  Reject kernel-to-kernel copies through copy_from_user(). (u8, 0x5a)
303  Reject kernel-to-kernel copies through copy_from_user(). (u16, 0x5a5b)
304  Reject kernel-to-kernel copies through copy_from_user(). (u32, 0x5a5b5c5d)
306  Reject kernel-to-kernel copies through copy_from_user(). (u64, 0x5a5b5c5d6a6b6c6d)
310  vm_munmap(user_addr, PAGE_SIZE * 2)
311  kfree(kmem)
313  If ret == 0 Then
314  pr_info("tests passed.\n")
315  Return 0
318  Return -EINVAL