Skip to contentSkip to conversation

mm: add NR_ZSMALLOC to vmstat

DISCUSSION Dan Carpenter 2 participants 2 messages Jun 6, 2016 – Jun 7, 2016 Memory management

lore
Share & tools
lore
#0 lore raw

Hello Minchan Kim,

The patch b37284200b39: "mm: add NR_ZSMALLOC to vmstat" from Jun 5, 2016, leads to the following static checker warning:

	mm/zsmalloc.c:1155 alloc_zspage()
	error: we previously assumed 'page' could be null (see line 1152)

mm/zsmalloc.c
1130 /*
1131 * Allocate a zspage for the given size class
1132 */
1133 static struct zspage *alloc_zspage(struct zs_pool *pool,
1134 struct size_class *class,
1135 gfp_t gfp)
1136 {

  1137          int i;
  1138          struct page *pages[ZS_MAX_PAGES_PER_ZSPAGE];
  1139          struct zspage *zspage = cache_alloc_zspage(pool, gfp);
  1140  
  1141          if (!zspage)
  1142                  return NULL;
  1143  
  1144          memset(zspage, 0, sizeof(struct zspage));
  1145          zspage->magic = ZSPAGE_MAGIC;
  1146          migrate_lock_init(zspage);
  1147  
  1148          for (i = 0; i < class->pages_per_zspage; i++) {
  1149                  struct page *page;
  1150  
  1151                  page = alloc_page(gfp);
  1152                  if (!page) {
                             ^^^^
  1153                          while (--i >= 0) {
  1154                                  __free_page(pages[i]);
  1155                                  dec_zone_page_state(page, NR_ZSMALLOC);
                                                            ^^^^

Potential NULL deref inside function call.

  1156                          }
  1157                          cache_free_zspage(pool, zspage);
  1158                          return NULL;

1159 }
1160
1161 inc_zone_page_state(page, NR_ZSMALLOC);
1162 pages[i] = page;
1163 }
1164
1165 create_page_chain(class, zspage, pages);
1166 init_zspage(class, zspage);
1167
1168 return zspage;
1169 }

regards,
dan carpenter

--
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>

#1 lore raw

Hello Dan,

Quoted 37 lines · Dan Carpenter

Hello Minchan Kim,

The patch b37284200b39: "mm: add NR_ZSMALLOC to vmstat" from Jun 5, 2016, leads to the following static checker warning:

	mm/zsmalloc.c:1155 alloc_zspage()
	error: we previously assumed 'page' could be null (see line 1152)

mm/zsmalloc.c
1130 /*
1131 * Allocate a zspage for the given size class
1132 */
1133 static struct zspage *alloc_zspage(struct zs_pool *pool,
1134 struct size_class *class,
1135 gfp_t gfp)
1136 {

  1137          int i;
  1138          struct page *pages[ZS_MAX_PAGES_PER_ZSPAGE];
  1139          struct zspage *zspage = cache_alloc_zspage(pool, gfp);
  1140  
  1141          if (!zspage)
  1142                  return NULL;
  1143  
  1144          memset(zspage, 0, sizeof(struct zspage));
  1145          zspage->magic = ZSPAGE_MAGIC;
  1146          migrate_lock_init(zspage);
  1147  
  1148          for (i = 0; i < class->pages_per_zspage; i++) {
  1149                  struct page *page;
  1150  
  1151                  page = alloc_page(gfp);
  1152                  if (!page) {
                             ^^^^
  1153                          while (--i >= 0) {
  1154                                  __free_page(pages[i]);
  1155                                  dec_zone_page_state(page, NR_ZSMALLOC);
                                                            ^^^^
Quoted 1 line

Potential NULL deref inside function call.

Strictly speaking, it shouldn't be a problem because zone bit encoded in page->flags is never changed although it is freed but I admit its' not good pracice. I will send fix.

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>