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:01
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:test_copy_struct_from_user

Proto:static int test_copy_struct_from_user(char *kmem, char __user *umem, size_t size)

Type:int

Parameter:

TypeParameterName
char *kmem
char __user *umem
size_tsize
108  ret = 0
109  char * umem_src = NULL, * expected = NULL
112  umem_src = kmalloc(size, GFP_KERNEL)
113  ret = test(umem_src == NULL, "kmalloc failed")
114  If ret Then Go to out_free
117  expected = kmalloc(size, GFP_KERNEL)
118  ret = test(expected == NULL, "kmalloc failed")
119  If ret Then Go to out_free
123  memset(umem_src, 0x3e, size)
124  ret |= test(copy_to_user(umem, umem_src, size), "legitimate copy_to_user failed")
128  ksize = size
129  usize = size
131  No 3D Now!(expected, umem_src, ksize)
133  memset(kmem, 0x0, size)
134  ret |= test(py_struct_from_user: copy a struct from userspace*@dst: Destination address, in kernel space, "copy_struct_from_user(usize == ksize) failed")
136  ret |= test(memcmp(kmem, expected, ksize), "copy_struct_from_user(usize == ksize) gives unexpected copy")
140  ksize = size
141  usize = size / 2
143  No 3D Now!(expected, umem_src, usize)
144  memset(expected + usize, 0x0, ksize - usize)
146  memset(kmem, 0x0, size)
147  ret |= test(py_struct_from_user: copy a struct from userspace*@dst: Destination address, in kernel space, "copy_struct_from_user(usize < ksize) failed")
149  ret |= test(memcmp(kmem, expected, ksize), "copy_struct_from_user(usize < ksize) gives unexpected copy")
153  ksize = size / 2
154  usize = size
156  memset(kmem, 0x0, size)
157  ret |= test(py_struct_from_user: copy a struct from userspace*@dst: Destination address, in kernel space != - E2BIG, "copy_struct_from_user(usize > ksize) didn't give E2BIG")
161  ksize = size / 2
162  usize = size
164  No 3D Now!(expected, umem_src, ksize)
165  ret |= test(lear_user - Zero a block of memory in user space.*@to: Destination address, in user space.*@n: Number of bytes to zero.* Zero a block of memory in user space.* Return: number of bytes that could not be cleared.* On success, this will be zero., "legitimate clear_user failed")
168  memset(kmem, 0x0, size)
169  ret |= test(py_struct_from_user: copy a struct from userspace*@dst: Destination address, in kernel space, "copy_struct_from_user(usize > ksize) failed")
171  ret |= test(memcmp(kmem, expected, ksize), "copy_struct_from_user(usize > ksize) gives unexpected copy")
174  out_free :
175  kfree(expected)
176  kfree(umem_src)
177  Return ret
Caller
NameDescribe
test_user_copy_init