mm/kasan: use {READ,WRITE}_MODE not true,false
Subsystems (2)
PATCH 1/1 mm/kasan: use {READ,WRITE}_MODE not true,false
When Kasan tell memory access is write or not, use true or false. This expression is simple and convenient.
But I think it is possible to more readable. and so change it.
--- mm/kasan/kasan.c | 32 ++++++++++++++++---------------- mm/kasan/kasan.h | 12 ++++++++++-- mm/kasan/report.c | 16 ++++++++-------- 3 files changed, 34 insertions(+), 26 deletions(-)
mm/kasan/kasan.c +16 -16
@@ -274,7 +274,7 @@ static __always_inline bool memory_is_poisoned(unsigned long addr, size_t size) } static __always_inline void check_memory_region_inline(unsigned long addr, -size_t size,bool write, +size_t size,enum acc_type type,unsigned long ret_ip) {if (unlikely (size ==0 ))
@@ -282,39 +282,39 @@ static __always_inline void check_memory_region_inline(unsigned long addr,if (unlikely ((void *)addr <kasan_shadow_to_mem ((void *)KASAN_SHADOW_START ))) { -kasan_report (addr, size, write, ret_ip); +kasan_report (addr, size, type, ret_ip);return ; }if (likely (!memory_is_poisoned (addr, size)))return ; -kasan_report (addr, size, write, ret_ip); +kasan_report (addr, size, type, ret_ip); }static void check_memory_region (unsigned long addr, -size_t size,bool write, +size_t size,enum acc_type type,unsigned long ret_ip) { -check_memory_region_inline (addr, size, write, ret_ip); +check_memory_region_inline (addr, size, type, ret_ip); }void kasan_check_read (const void *p,unsigned int size) { -check_memory_region ((unsigned long )p, size, false, _RET_IP_); +check_memory_region ((unsigned long )p, size,READ_MODE , _RET_IP_); }EXPORT_SYMBOL (kasan_check_read);void kasan_check_write (const void *p,unsigned int size) { -check_memory_region ((unsigned long )p, size, true, _RET_IP_); +check_memory_region ((unsigned long )p, size,WRITE_MODE , _RET_IP_); }EXPORT_SYMBOL (kasan_check_write);#undef memsetvoid *memset (void *addr,int c,size_t len) { -check_memory_region ((unsigned long )addr, len, true, _RET_IP_); +check_memory_region ((unsigned long )addr, len,WRITE_MODE , _RET_IP_);return __memset (addr, c, len); }
@@ -322,8 +322,8 @@ void *memset(void *addr, int c, size_t len)#undef memmovevoid *memmove (void *dest,const void *src,size_t len) { -check_memory_region ((unsigned long )src, len, false, _RET_IP_); -check_memory_region ((unsigned long )dest, len, true, _RET_IP_); +check_memory_region ((unsigned long )src, len,READ_MODE , _RET_IP_); +check_memory_region ((unsigned long )dest, len,WRITE_MODE , _RET_IP_);return __memmove (dest, src, len); }
@@ -331,8 +331,8 @@ void *memmove(void *dest, const void *src, size_t len)#undef memcpyvoid *memcpy (void *dest,const void *src,size_t len) { -check_memory_region ((unsigned long )src, len, false, _RET_IP_); -check_memory_region ((unsigned long )dest, len, true, _RET_IP_); +check_memory_region ((unsigned long )src, len,READ_MODE , _RET_IP_); +check_memory_region ((unsigned long )dest, len,WRITE_MODE , _RET_IP_);return __memcpy (dest, src, len); }
@@ -709,7 +709,7 @@ EXPORT_SYMBOL(__asan_unregister_globals);#define DEFINE_ASAN_LOAD_STORE (size) \ void __asan_load##size(unsigned long addr) \ { \ - check_memory_region_inline(addr, size, false, _RET_IP_);\ + check_memory_region_inline(addr, size, READ_MODE, _RET_IP_);\ } \ EXPORT_SYMBOL(__asan_load##size); \ __alias(__asan_load##size) \
@@ -717,7 +717,7 @@ EXPORT_SYMBOL(__asan_unregister_globals); EXPORT_SYMBOL(__asan_load##size##_noabort); \ void __asan_store##size(unsigned long addr) \ { \ - check_memory_region_inline(addr, size, true, _RET_IP_); \ + check_memory_region_inline(addr, size, WRITE_MODE, _RET_IP_);\ } \ EXPORT_SYMBOL(__asan_store##size); \ __alias(__asan_store##size) \
@@ -732,7 +732,7 @@ DEFINE_ASAN_LOAD_STORE(16);void __asan_loadN (unsigned long addr,size_t size) { -check_memory_region (addr, size, false, _RET_IP_); +check_memory_region (addr, size,READ_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_loadN);
@@ -742,7 +742,7 @@ EXPORT_SYMBOL(__asan_loadN_noabort);void __asan_storeN (unsigned long addr,size_t size) { -check_memory_region (addr, size, true, _RET_IP_); +check_memory_region (addr, size,WRITE_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_storeN);
mm/kasan/kasan.h +10 -2
@@ -27,11 +27,19 @@#define KASAN_ABI_VERSION 1#endif +/* +* Distinguish memory access +*/ +enum acc_type { +READ_MODE , +WRITE_MODE +}; +struct kasan_access_info {const void *access_addr;const void *first_bad_addr;size_t access_size; -bool is_write; +enum acc_type access_type;unsigned long ip; };
@@ -109,7 +117,7 @@ static inline bool kasan_report_enabled(void) }void kasan_report (unsigned long addr,size_t size, -bool is_write,unsigned long ip); +enum acc_type type,unsigned long ip);#ifdef CONFIG_SLAB void quarantine_put (struct kasan_free_meta *info,struct kmem_cache *cache);
mm/kasan/report.c +8 -8
@@ -96,7 +96,7 @@ static void print_error_description(struct kasan_access_info *info) bug_type, (void *)info->ip, info->access_addr);pr_err ("%s of size %zu by task %s/%d\n" , - info->is_write ?"Write" :"Read" , + info->access_type ==WRITE_MODE ?"Write" :"Read" , info->access_size, current->comm,task_pid_nr (current)); }
@@ -267,7 +267,7 @@ static void kasan_report_error(struct kasan_access_info *info)pr_err ("BUG: KASAN: %s on address %p\n" , bug_type, info->access_addr);pr_err ("%s of size %zu by task %s/%d\n" , - info->is_write ?"Write" :"Read" , + info->access_type ==WRITE_MODE ?"Write" :"Read" , info->access_size, current->comm,task_pid_nr (current));dump_stack ();
@@ -283,7 +283,7 @@ static void kasan_report_error(struct kasan_access_info *info) }void kasan_report (unsigned long addr,size_t size, -bool is_write,unsigned long ip) +enum acc_type type,unsigned long ip) {struct kasan_access_info info;
@@ -292,7 +292,7 @@ void kasan_report(unsigned long addr, size_t size, info.access_addr = (void *)addr; info.access_size = size; - info.is_write = is_write; + info.access_type = type; info.ip = ip;kasan_report_error (&info);
@@ -302,14 +302,14 @@ void kasan_report(unsigned long addr, size_t size,#define DEFINE_ASAN_REPORT_LOAD (size) \ void __asan_report_load##size##_noabort(unsigned long addr) \ { \ - kasan_report(addr, size, false, _RET_IP_); \ + kasan_report(addr, size, READ_MODE, _RET_IP_); \ } \ EXPORT_SYMBOL(__asan_report_load##size##_noabort)#define DEFINE_ASAN_REPORT_STORE (size) \ void __asan_report_store##size##_noabort(unsigned long addr) \ { \ - kasan_report(addr, size, true, _RET_IP_); \ + kasan_report(addr, size, WRITE_MODE, _RET_IP_); \ } \ EXPORT_SYMBOL(__asan_report_store##size##_noabort)
@@ -326,12 +326,12 @@ DEFINE_ASAN_REPORT_STORE(16);void __asan_report_load_n_noabort (unsigned long addr,size_t size) { -kasan_report (addr, size, false, _RET_IP_); +kasan_report (addr, size,READ_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_report_load_n_noabort);void __asan_report_store_n_noabort (unsigned long addr,size_t size) { -kasan_report (addr, size, true, _RET_IP_); +kasan_report (addr, size,WRITE_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_report_store_n_noabort);
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Dmitry Vyukov
reviewerQuoted 226 lines · seokhoon.yoon
When Kasan tell memory access is write or not, use true or false. This expression is simple and convenient.
But I think it is possible to more readable. and so change it.
Signed-off-by seokhoon.yoon <[email protected]>--- mm/kasan/kasan.c | 32 ++++++++++++++++---------------- mm/kasan/kasan.h | 12 ++++++++++-- mm/kasan/report.c | 16 ++++++++-------- 3 files changed, 34 insertions(+), 26 deletions(-)mm/kasan/kasan.c +16
-16@@ -274,7 +274,7 @@ static __always_inline bool memory_is_poisoned(unsigned long addr, size_t size) } static __always_inline void check_memory_region_inline(unsigned long addr, -size_t size,bool write, +size_t size,enum acc_type type,unsigned long ret_ip) {if (unlikely (size ==0 ))@@ -282,39 +282,39 @@ static __always_inline void check_memory_region_inline(unsigned long addr,if (unlikely ((void *)addr <kasan_shadow_to_mem ((void *)KASAN_SHADOW_START ))) { -kasan_report (addr, size, write, ret_ip); +kasan_report (addr, size, type, ret_ip);return ; }if (likely (!memory_is_poisoned (addr, size)))return ; -kasan_report (addr, size, write, ret_ip); +kasan_report (addr, size, type, ret_ip); }static void check_memory_region (unsigned long addr, -size_t size,bool write, +size_t size,enum acc_type type,unsigned long ret_ip) { -check_memory_region_inline (addr, size, write, ret_ip); +check_memory_region_inline (addr, size, type, ret_ip); }void kasan_check_read (const void *p,unsigned int size) { -check_memory_region ((unsigned long )p, size, false, _RET_IP_); +check_memory_region ((unsigned long )p, size,READ_MODE , _RET_IP_); }EXPORT_SYMBOL (kasan_check_read);void kasan_check_write (const void *p,unsigned int size) { -check_memory_region ((unsigned long )p, size, true, _RET_IP_); +check_memory_region ((unsigned long )p, size,WRITE_MODE , _RET_IP_); }EXPORT_SYMBOL (kasan_check_write);#undef memsetvoid *memset (void *addr,int c,size_t len) { -check_memory_region ((unsigned long )addr, len, true, _RET_IP_); +check_memory_region ((unsigned long )addr, len,WRITE_MODE , _RET_IP_);return __memset (addr, c, len); }@@ -322,8 +322,8 @@ void *memset(void *addr, int c, size_t len)#undef memmovevoid *memmove (void *dest,const void *src,size_t len) { -check_memory_region ((unsigned long )src, len, false, _RET_IP_); -check_memory_region ((unsigned long )dest, len, true, _RET_IP_); +check_memory_region ((unsigned long )src, len,READ_MODE , _RET_IP_); +check_memory_region ((unsigned long )dest, len,WRITE_MODE , _RET_IP_);return __memmove (dest, src, len); }@@ -331,8 +331,8 @@ void *memmove(void *dest, const void *src, size_t len)#undef memcpyvoid *memcpy (void *dest,const void *src,size_t len) { -check_memory_region ((unsigned long )src, len, false, _RET_IP_); -check_memory_region ((unsigned long )dest, len, true, _RET_IP_); +check_memory_region ((unsigned long )src, len,READ_MODE , _RET_IP_); +check_memory_region ((unsigned long )dest, len,WRITE_MODE , _RET_IP_);return __memcpy (dest, src, len); }@@ -709,7 +709,7 @@ EXPORT_SYMBOL(__asan_unregister_globals);#define DEFINE_ASAN_LOAD_STORE (size) \ void __asan_load##size(unsigned long addr) \ { \ - check_memory_region_inline(addr, size, false, _RET_IP_);\ + check_memory_region_inline(addr, size, READ_MODE, _RET_IP_);\ } \ EXPORT_SYMBOL(__asan_load##size); \ __alias(__asan_load##size) \@@ -717,7 +717,7 @@ EXPORT_SYMBOL(__asan_unregister_globals); EXPORT_SYMBOL(__asan_load##size##_noabort); \ void __asan_store##size(unsigned long addr) \ { \ - check_memory_region_inline(addr, size, true, _RET_IP_); \ + check_memory_region_inline(addr, size, WRITE_MODE, _RET_IP_);\ } \ EXPORT_SYMBOL(__asan_store##size); \ __alias(__asan_store##size) \@@ -732,7 +732,7 @@ DEFINE_ASAN_LOAD_STORE(16);void __asan_loadN (unsigned long addr,size_t size) { -check_memory_region (addr, size, false, _RET_IP_); +check_memory_region (addr, size,READ_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_loadN);@@ -742,7 +742,7 @@ EXPORT_SYMBOL(__asan_loadN_noabort);void __asan_storeN (unsigned long addr,size_t size) { -check_memory_region (addr, size, true, _RET_IP_); +check_memory_region (addr, size,WRITE_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_storeN);mm/kasan/kasan.h +10
-2@@ -27,11 +27,19 @@#define KASAN_ABI_VERSION 1#endif +/* +* Distinguish memory access +*/ +enum acc_type { +READ_MODE , +WRITE_MODE +}; +struct kasan_access_info {const void *access_addr;const void *first_bad_addr;size_t access_size; -bool is_write; +enum acc_type access_type;unsigned long ip; };@@ -109,7 +117,7 @@ static inline bool kasan_report_enabled(void) }void kasan_report (unsigned long addr,size_t size, -bool is_write,unsigned long ip); +enum acc_type type,unsigned long ip);#ifdef CONFIG_SLAB void quarantine_put (struct kasan_free_meta *info,struct kmem_cache *cache);mm/kasan/report.c +6
-7@@ -96,7 +96,7 @@ static void print_error_description(struct kasan_access_info *info) bug_type, (void *)info->ip, info->access_addr);pr_err ("%s of size %zu by task %s/%d\n" , - info->is_write ?"Write" :"Read" , + info->access_type ==WRITE_MODE ?"Write" :"Read" , info->access_size, current->comm,task_pid_nr (current)); }@@ -267,7 +267,7 @@ static void kasan_report_error(struct kasan_access_info *info)pr_err ("BUG: KASAN: %s on address %p\n" , bug_type, info->access_addr);pr_err ("%s of size %zu by task %s/%d\n" , - info->is_write ?"Write" :"Read" , + info->access_type ==WRITE_MODE ?"Write" :"Read" , info->access_size, current->comm,task_pid_nr (current));dump_stack ();@@ -283,7 +283,7 @@ static void kasan_report_error(struct kasan_access_info *info) }void kasan_report (unsigned long addr,size_t size, -bool is_write,unsigned long ip) +enum acc_type type,unsigned long ip) {struct kasan_access_info info;@@ -292,7 +292,7 @@ void kasan_report(unsigned long addr, size_t size, info.access_addr = (void *)addr; info.access_size = size; - info.is_write = is_write; + info.access_type = type; info.ip = ip;kasan_report_error (&info);@@ -302,14 +302,14 @@ void kasan_report(unsigned long addr, size_t size,#define DEFINE_ASAN_REPORT_LOAD (size) \ void __asan_report_load##size##_noabort(unsigned long addr) \ { \ - kasan_report(addr, size, false, _RET_IP_); \ + kasan_report(addr, size, READ_MODE, _RET_IP_); \ } \ EXPORT_SYMBOL(__asan_report_load##size##_noabort)#define DEFINE_ASAN_REPORT_STORE (size) \ void __asan_report_store##size##_noabort(unsigned long addr) \ { \ - kasan_report(addr, size, true, _RET_IP_); \ + kasan_report(addr, size, WRITE_MODE, _RET_IP_); \ } \ EXPORT_SYMBOL(__asan_report_store##size##_noabort)@@ -326,12 +326,12 @@ DEFINE_ASAN_REPORT_STORE(16);void __asan_report_load_n_noabort (unsigned long addr,size_t size) { -kasan_report (addr, size, false, _RET_IP_);
mm/kasan/report.c DEFINE_ASAN_REPORT_STORE(16); · line 337
Quoted 10 lines
mm/kasan/report.c +2
-1+kasan_report (addr, size,READ_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_report_load_n_noabort);void __asan_report_store_n_noabort (unsigned long addr,size_t size) { -kasan_report (addr, size, true, _RET_IP_); +kasan_report (addr, size,WRITE_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_report_store_n_noabort);
Hello seokhoon.yoon,
Where exactly do you hit readability problems?
I would say that the only problematic place is where we initialize the value:
kasan_report(addr, size, true, _RET_IP_);
check_memory_region(addr, size, true, _RET_IP_);Here it is really difficult to say what true/false mean. Even if you know that it is access type, you don't necessary remember if true means write or read. That could be solved by adding comments:
kasan_report(addr, size, /* write = */ true, _RET_IP_);
In all other places one sees that we are talking about "write".
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
2016-06-05 21:49 GMT+09:00 Dmitry Vyukov <[email protected]>:
Quoted 259 lines · seokhoon.yoon
mm/kasan/kasan.c static __always_inline bool
Quoted 17 lines
When Kasan tell memory access is write or not, use true or false. This expression is simple and convenient.
But I think it is possible to more readable. and so change it.
Signed-off-by seokhoon.yoon <[email protected]>--- mm/kasan/kasan.c | 32 ++++++++++++++++---------------- mm/kasan/kasan.h | 12 ++++++++++-- mm/kasan/report.c | 16 ++++++++-------- 3 files changed, 34 insertions(+), 26 deletions(-)mm/kasan/kasan.c +0
-0@@ -274,7 +274,7 @@ static __always_inline bool
memory_is_poisoned(unsigned long addr, size_t size)mm/kasan/kasan.c static __always_inline bool · line 276
Quoted 3 lines
mm/kasan/kasan.c +0
-0} static __always_inline void check_memory_region_inline(unsigned longaddr,
mm/kasan/kasan.c static __always_inline bool · line 277
Quoted 2 lines
mm/kasan/kasan.c +1
-1- size_t size, bool write, +size_t size, enum
acc_typetype,mm/kasan/kasan.c static __always_inline void
Quoted 4 lines
mm/kasan/kasan.c +0
-0unsigned long ret_ip) {if (unlikely (size ==0 ))@@ -282,39 +282,39 @@ static __always_inline voidcheck_memory_region_inline(unsigned long addr,
Quoted 25 lines
mm/kasan/kasan.c +4
-4if (unlikely ((void *)addr <kasan_shadow_to_mem ((void *)KASAN_SHADOW_START ))) { -kasan_report (addr, size, write, ret_ip); +kasan_report (addr, size, type, ret_ip);return ; }if (likely (!memory_is_poisoned (addr, size)))return ; -kasan_report (addr, size, write, ret_ip); +kasan_report (addr, size, type, ret_ip); }static void check_memory_region (unsigned long addr, -size_t size,bool write, +size_t size,enum acc_type type,unsigned long ret_ip) { -check_memory_region_inline (addr, size, write, ret_ip); +check_memory_region_inline (addr, size, type, ret_ip); }void kasan_check_read (const void *p,unsigned int size)mm/kasan/kasan.c static __always_inline void check_memory_region_inline(unsigned long addr,
Quoted 10 lines
mm/kasan/kasan.c +2
-2{ -check_memory_region ((unsigned long )p, size, false, _RET_IP_); +check_memory_region ((unsigned long )p, size,READ_MODE , _RET_IP_); }EXPORT_SYMBOL (kasan_check_read);void kasan_check_write (const void *p,unsigned int size) { -check_memory_region ((unsigned long )p, size, true, _RET_IP_); + check_memory_region((unsigned long)p, size, WRITE_MODE,_RET_IP_);
mm/kasan/kasan.c static __always_inline void check_memory_region_inline(unsigned long addr,
Quoted 8 lines
mm/kasan/kasan.c +1
-1}EXPORT_SYMBOL (kasan_check_write);#undef memsetvoid *memset (void *addr,int c,size_t len) { -check_memory_region ((unsigned long )addr, len, true, _RET_IP_); + check_memory_region((unsigned long)addr, len, WRITE_MODE,_RET_IP_);
mm/kasan/kasan.c void *memset(void *addr, int c, size_t len) · line 325
Quoted 10 lines
mm/kasan/kasan.c +1
-2return __memset (addr, c, len); }@@ -322,8 +322,8 @@ void *memset(void *addr, int c, size_t len)#undef memmovevoid *memmove (void *dest,const void *src,size_t len) { -check_memory_region ((unsigned long )src, len, false, _RET_IP_); -check_memory_region ((unsigned long )dest, len, true, _RET_IP_); + check_memory_region((unsigned long)src, len, READ_MODE,_RET_IP_);
mm/kasan/kasan.c void *memset(void *addr, int c, size_t len) · line 326
Quoted 1 line
mm/kasan/kasan.c +1
-0+ check_memory_region((unsigned long)dest, len, WRITE_MODE,_RET_IP_);
mm/kasan/kasan.c void *memmove(void *dest, const void *src, size_t
Quoted 4 lines
mm/kasan/kasan.c +0
-0return __memmove (dest, src, len); }@@ -331,8 +331,8 @@ void *memmove(void *dest, const void *src, size_tlen)
mm/kasan/kasan.c void *memmove(void *dest, const void *src, size_t len)
Quoted 6 lines
mm/kasan/kasan.c +1
-2#undef memcpyvoid *memcpy (void *dest,const void *src,size_t len) { -check_memory_region ((unsigned long )src, len, false, _RET_IP_); -check_memory_region ((unsigned long )dest, len, true, _RET_IP_); + check_memory_region((unsigned long)src, len, READ_MODE,_RET_IP_);
mm/kasan/kasan.c void *memmove(void *dest, const void *src, size_t · line 335
Quoted 1 line
mm/kasan/kasan.c +1
-0+ check_memory_region((unsigned long)dest, len, WRITE_MODE,_RET_IP_);
mm/kasan/kasan.c EXPORT_SYMBOL(__asan_unregister_globals); · line 712
Quoted 9 lines
mm/kasan/kasan.c +1
-1return __memcpy (dest, src, len); }@@ -709,7 +709,7 @@ EXPORT_SYMBOL(__asan_unregister_globals);#define DEFINE_ASAN_LOAD_STORE (size) \ void __asan_load##size(unsigned long addr) \ { \ - check_memory_region_inline(addr, size, false, _RET_IP_);\ + check_memory_region_inline(addr, size, READ_MODE,_RET_IP_);\
mm/kasan/kasan.c EXPORT_SYMBOL(__asan_unregister_globals); · line 720
Quoted 9 lines
mm/kasan/kasan.c +1
-1} \ EXPORT_SYMBOL(__asan_load##size); \ __alias(__asan_load##size) \@@ -717,7 +717,7 @@ EXPORT_SYMBOL(__asan_unregister_globals); EXPORT_SYMBOL(__asan_load##size##_noabort); \ void __asan_store##size(unsigned long addr) \ { \ - check_memory_region_inline(addr, size, true, _RET_IP_); \ + check_memory_region_inline(addr, size, WRITE_MODE,_RET_IP_);\
Quoted 47 lines
mm/kasan/kasan.c +2
-2} \ EXPORT_SYMBOL(__asan_store##size); \ __alias(__asan_store##size) \@@ -732,7 +732,7 @@ DEFINE_ASAN_LOAD_STORE(16);void __asan_loadN (unsigned long addr,size_t size) { -check_memory_region (addr, size, false, _RET_IP_); +check_memory_region (addr, size,READ_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_loadN);@@ -742,7 +742,7 @@ EXPORT_SYMBOL(__asan_loadN_noabort);void __asan_storeN (unsigned long addr,size_t size) { -check_memory_region (addr, size, true, _RET_IP_); +check_memory_region (addr, size,WRITE_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_storeN);mm/kasan/kasan.h +9
-1@@ -27,11 +27,19 @@#define KASAN_ABI_VERSION 1#endif +/* +* Distinguish memory access +*/ +enum acc_type { +READ_MODE , +WRITE_MODE +}; +struct kasan_access_info {const void *access_addr;const void *first_bad_addr;size_t access_size; -bool is_write; +enum acc_type access_type;unsigned long ip; };mm/kasan/kasan.h static inline bool kasan_report_enabled(void) · line 123
Quoted 8 lines
mm/kasan/kasan.h +1
-1@@ -109,7 +117,7 @@ static inline bool kasan_report_enabled(void) }void kasan_report (unsigned long addr,size_t size, -bool is_write,unsigned long ip); +enum acc_type type,unsigned long ip);#ifdef CONFIG_SLAB void quarantine_put(struct kasan_free_meta *info, struct kmem_cache*cache);
mm/kasan/report.c static void print_error_description(struct
Quoted 5 lines
mm/kasan/report.c +0
-0@@ -96,7 +96,7 @@ static void print_error_description(struct
kasan_access_info*info)mm/kasan/report.c static void kasan_report_error(struct
Quoted 9 lines
mm/kasan/report.c +1
-1bug_type, (void *)info->ip, info->access_addr);pr_err ("%s of size %zu by task %s/%d\n" , - info->is_write ?"Write" :"Read" , + info->access_type ==WRITE_MODE ?"Write" :"Read" , info->access_size, current->comm,task_pid_nr (current)); }@@ -267,7 +267,7 @@ static void kasan_report_error(struct
kasan_access_info*info)mm/kasan/report.c static void kasan_report_error(struct kasan_access_info *info)
Quoted 5 lines
mm/kasan/report.c +1
-1pr_err ("BUG: KASAN: %s on address %p\n" , bug_type, info->access_addr); pr_err("%s of size %zu by task %s/%d\n", - info->is_write ? "Write" : "Read", + info->access_type == WRITE_MODE ? "Write" :"Read",
mm/kasan/report.c static void kasan_report_error(struct
Quoted 4 lines
mm/kasan/report.c +0
-0info->access_size, current->comm, task_pid_nr(current));dump_stack ();@@ -283,7 +283,7 @@ static void kasan_report_error(struct
kasan_access_info*info)Quoted 39 lines
mm/kasan/report.c +4
-5}void kasan_report (unsigned long addr,size_t size, -bool is_write,unsigned long ip) +enum acc_type type,unsigned long ip) {struct kasan_access_info info;@@ -292,7 +292,7 @@ void kasan_report(unsigned long addr, size_t size, info.access_addr = (void *)addr; info.access_size = size; - info.is_write = is_write; + info.access_type = type; info.ip = ip;kasan_report_error (&info);@@ -302,14 +302,14 @@ void kasan_report(unsigned long addr, size_t size,#define DEFINE_ASAN_REPORT_LOAD (size) \ void __asan_report_load##size##_noabort(unsigned long addr) \ { \ - kasan_report(addr, size, false, _RET_IP_); \ + kasan_report(addr, size, READ_MODE, _RET_IP_); \ } \ EXPORT_SYMBOL(__asan_report_load##size##_noabort)#define DEFINE_ASAN_REPORT_STORE (size) \ void __asan_report_store##size##_noabort(unsigned long addr) \ { \ - kasan_report(addr, size, true, _RET_IP_); \ + kasan_report(addr, size, WRITE_MODE, _RET_IP_); \ } \ EXPORT_SYMBOL(__asan_report_store##size##_noabort)@@ -326,12 +326,12 @@ DEFINE_ASAN_REPORT_STORE(16);void __asan_report_load_n_noabort (unsigned long addr,size_t size) { -kasan_report (addr, size, false, _RET_IP_);mm/kasan/report.c DEFINE_ASAN_REPORT_STORE(16); · line 337
Quoted 10 lines
mm/kasan/report.c +2
-1+kasan_report (addr, size,READ_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_report_load_n_noabort);void __asan_report_store_n_noabort (unsigned long addr,size_t size) { -kasan_report (addr, size, true, _RET_IP_); +kasan_report (addr, size,WRITE_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_report_store_n_noabort);Hello seokhoon.yoon,
Quoted 1 line
Hi Dmitry,
thanks for your replies.
Quoted 3 lines
Where exactly do you hit readability problems?
I don`t hit readablity problem,but kasan need to abstract this expression. I think more abstraction give us more readablity. isn't it? :)
Quoted 6 lines
I would say that the only problematic place is where we initialize the value:
kasan_report(addr, size, true, _RET_IP_); check_memory_region(addr, size, true, _RET_IP_);
Here it is really difficult to say what true/false mean. Even if you
Quoted 1 line
know that it is access type, you don't necessary remember if true
means write or read. That could be solved by adding comments:
Quoted 4 lines
kasan_report(addr, size, /* write = */ true, _RET_IP_);In all other places one sees that we are talking about "write".
thanks.
Dmitry Vyukov
reviewerQuoted 282 lines · SeokHoon Yoon
2016-06-05 21:49 GMT+09:00 Dmitry Vyukov <[email protected]>:
Quoted 265 lines · seokhoon.yoon
Quoted 263 lines
When Kasan tell memory access is write or not, use true or false. This expression is simple and convenient.
But I think it is possible to more readable. and so change it.
Signed-off-by seokhoon.yoon <[email protected]>--- mm/kasan/kasan.c | 32 ++++++++++++++++---------------- mm/kasan/kasan.h | 12 ++++++++++-- mm/kasan/report.c | 16 ++++++++-------- 3 files changed, 34 insertions(+), 26 deletions(-)mm/kasan/kasan.c +1
-1@@ -274,7 +274,7 @@ static __always_inline bool memory_is_poisoned(unsigned long addr, size_t size) } static __always_inline void check_memory_region_inline(unsigned long addr, - size_t size, bool write, + size_t size, enum acc_type type,unsigned long
ret_ip){ if (unlikely(size == 0))mm/kasan/kasan.c +7
-7@@ -282,39 +282,39 @@ static __always_inline void check_memory_region_inline(unsigned long addr, if (unlikely((void *)addr < kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) { -kasan_report (addr, size, write, ret_ip); +kasan_report (addr, size, type, ret_ip);return ; }if (likely (!memory_is_poisoned (addr, size)))return ; -kasan_report (addr, size, write, ret_ip); +kasan_report (addr, size, type, ret_ip); }static void check_memory_region (unsigned long addr, -size_t size,bool write, +size_t size,enum acc_type type,unsigned long ret_ip) { -check_memory_region_inline (addr, size, write, ret_ip); +check_memory_region_inline (addr, size, type, ret_ip); }void kasan_check_read (const void *p,unsigned int size) { -check_memory_region ((unsigned long )p, size, false, _RET_IP_); +check_memory_region ((unsigned long )p, size,READ_MODE , _RET_IP_); }EXPORT_SYMBOL (kasan_check_read);void kasan_check_write (const void *p,unsigned int size) { -check_memory_region ((unsigned long )p, size, true, _RET_IP_); +check_memory_region ((unsigned long )p, size,WRITE_MODE , _RET_IP_); }EXPORT_SYMBOL (kasan_check_write);#undef memsetvoid *memset (void *addr,int c,size_t len) { -check_memory_region ((unsigned long )addr, len, true, _RET_IP_); + check_memory_region((unsigned long)addr, len, WRITE_MODE,_RET_IP_);
return __memset(addr, c, len);}
mm/kasan/kasan.c +2
-2@@ -322,8 +322,8 @@ void *memset(void *addr, int c, size_t len)#undef memmovevoid *memmove (void *dest,const void *src,size_t len) { -check_memory_region ((unsigned long )src, len, false, _RET_IP_); -check_memory_region ((unsigned long )dest, len, true, _RET_IP_); +check_memory_region ((unsigned long )src, len,READ_MODE , _RET_IP_); +check_memory_region ((unsigned long )dest, len,WRITE_MODE , _RET_IP_);return __memmove(dest, src, len);}
mm/kasan/kasan.c +2
-2@@ -331,8 +331,8 @@ void *memmove(void *dest, const void *src, size_t len)#undef memcpyvoid *memcpy (void *dest,const void *src,size_t len) { -check_memory_region ((unsigned long )src, len, false, _RET_IP_); -check_memory_region ((unsigned long )dest, len, true, _RET_IP_); +check_memory_region ((unsigned long )src, len,READ_MODE , _RET_IP_); +check_memory_region ((unsigned long )dest, len,WRITE_MODE , _RET_IP_);return __memcpy(dest, src, len);}
mm/kasan/kasan.c +0
-1@@ -709,7 +709,7 @@ EXPORT_SYMBOL(__asan_unregister_globals);#define DEFINE_ASAN_LOAD_STORE (size) \ void __asan_load##size(unsigned long addr) \ { \ - check_memory_region_inline(addr, size, false,_RET_IP_);\
+ check_memory_region_inline(addr, size,READ_MODE,_RET_IP_);\ } \ EXPORT_SYMBOL(__asan_load##size); \ __alias(__asan_load##size)\
mm/kasan/kasan.c +0
-1@@ -717,7 +717,7 @@ EXPORT_SYMBOL(__asan_unregister_globals); EXPORT_SYMBOL(__asan_load##size##_noabort); \ void __asan_store##size(unsigned long addr) \ { \ -check_memory_region_inline (addr, size, true, _RET_IP_);\
+ check_memory_region_inline(addr, size,WRITE_MODE,_RET_IP_);\ } \ EXPORT_SYMBOL(__asan_store##size); \ __alias(__asan_store##size)\
mm/kasan/kasan.c +2
-2@@ -732,7 +732,7 @@ DEFINE_ASAN_LOAD_STORE(16);void __asan_loadN (unsigned long addr,size_t size) { -check_memory_region (addr, size, false, _RET_IP_); +check_memory_region (addr, size,READ_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_loadN);@@ -742,7 +742,7 @@ EXPORT_SYMBOL(__asan_loadN_noabort);void __asan_storeN (unsigned long addr,size_t size) { -check_memory_region (addr, size, true, _RET_IP_); +check_memory_region (addr, size,WRITE_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_storeN);mm/kasan/kasan.h +10
-2@@ -27,11 +27,19 @@#define KASAN_ABI_VERSION 1#endif +/* +* Distinguish memory access +*/ +enum acc_type { +READ_MODE , +WRITE_MODE +}; +struct kasan_access_info {const void *access_addr;const void *first_bad_addr;size_t access_size; -bool is_write; +enum acc_type access_type;unsigned long ip; };@@ -109,7 +117,7 @@ static inline bool kasan_report_enabled(void) }void kasan_report (unsigned long addr,size_t size, -bool is_write,unsigned long ip); +enum acc_type type,unsigned long ip);#ifdef CONFIG_SLAB void quarantine_put(struct kasan_free_meta *info, struct kmem_cache*cache);
mm/kasan/report.c +2
-2@@ -96,7 +96,7 @@ static void print_error_description(struct kasan_access_info *info) bug_type, (void *)info->ip, info->access_addr);pr_err ("%s of size %zu by task %s/%d\n" , - info->is_write ?"Write" :"Read" , + info->access_type ==WRITE_MODE ?"Write" :"Read" , info->access_size, current->comm,task_pid_nr (current)); }@@ -267,7 +267,7 @@ static void kasan_report_error(struct kasan_access_info *info) pr_err("BUG: KASAN: %s on address %p\n", bug_type, info->access_addr); pr_err("%s of size %zu by task %s/%d\n", - info->is_write ? "Write" : "Read", + info->access_type == WRITE_MODE ? "Write" : "Read", info->access_size, current->comm,task_pid_nr(current)); dump_stack();mm/kasan/report.c +5
-5@@ -283,7 +283,7 @@ static void kasan_report_error(struct kasan_access_info *info) }void kasan_report (unsigned long addr,size_t size, -bool is_write,unsigned long ip) +enum acc_type type,unsigned long ip) {struct kasan_access_info info;@@ -292,7 +292,7 @@ void kasan_report(unsigned long addr, size_t size, info.access_addr = (void *)addr; info.access_size = size; - info.is_write = is_write; + info.access_type = type; info.ip = ip;kasan_report_error (&info);@@ -302,14 +302,14 @@ void kasan_report(unsigned long addr, size_t size,#define DEFINE_ASAN_REPORT_LOAD (size) \ void __asan_report_load##size##_noabort(unsigned long addr) \ { \ - kasan_report(addr, size, false, _RET_IP_); \ + kasan_report(addr, size, READ_MODE, _RET_IP_); \ } \ EXPORT_SYMBOL(__asan_report_load##size##_noabort)#define DEFINE_ASAN_REPORT_STORE (size) \ void __asan_report_store##size##_noabort(unsigned long addr) \ { \ - kasan_report(addr, size, true, _RET_IP_); \ + kasan_report(addr, size, WRITE_MODE, _RET_IP_); \ } \ EXPORT_SYMBOL(__asan_report_store##size##_noabort)@@ -326,12 +326,12 @@ DEFINE_ASAN_REPORT_STORE(16);void __asan_report_load_n_noabort (unsigned long addr,size_t size) { -kasan_report (addr, size, false, _RET_IP_); +kasan_report (addr, size,READ_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_report_load_n_noabort);Quoted 10 lines
mm/kasan/report.c DEFINE_ASAN_REPORT_STORE(16); · line 337
Quoted 6 lines
mm/kasan/report.c +1
-1void __asan_report_store_n_noabort (unsigned long addr,size_t size) { -kasan_report (addr, size, true, _RET_IP_); +kasan_report (addr, size,WRITE_MODE , _RET_IP_); }EXPORT_SYMBOL (__asan_report_store_n_noabort);Hello seokhoon.yoon,
Hi Dmitry,
thanks for your replies.Quoted 2 lines
Quoted 5 lines
Quoted 1 line
Where exactly do you hit readability problems?
I don`t hit readablity problem,but kasan need to abstract this expression. I think more abstraction give us more readablity. isn't it? :)
Keeping it simple also gives readability.
Quoted 9 lines
Quoted 9 lines
I would say that the only problematic place is where we initialize the value:
kasan_report(addr, size, true, _RET_IP_); check_memory_region(addr, size, true, _RET_IP_);Here it is really difficult to say what true/false mean. Even if you know that it is access type, you don't necessary remember if true
Quoted 8 lines
Quoted 5 lines
means write or read. That could be solved by adding comments:
kasan_report(addr, size, /* write = */ true, _RET_IP_);In all other places one sees that we are talking about "write".
thanks.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>