Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm: Constify struct dm_block_validator

'struct dm_block_validator' are not modified in these drivers.

Constifying this structure moves some data to a read-only section, so
increase overall security.

On a x86_64, with allmodconfig, as an example:

Before:
======
text data bss dec hex filename
32047 920 16 32983 80d7 drivers/md/dm-cache-metadata.o

After:
=====
text data bss dec hex filename
32075 896 16 32987 80db drivers/md/dm-cache-metadata.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

authored by

Christophe JAILLET and committed by
Mikulas Patocka
0b60be16 fb098768

+46 -44
+3 -3
drivers/md/dm-cache-metadata.c
··· 170 170 */ 171 171 #define SUPERBLOCK_CSUM_XOR 9031977 172 172 173 - static void sb_prepare_for_write(struct dm_block_validator *v, 173 + static void sb_prepare_for_write(const struct dm_block_validator *v, 174 174 struct dm_block *b, 175 175 size_t sb_block_size) 176 176 { ··· 195 195 return 0; 196 196 } 197 197 198 - static int sb_check(struct dm_block_validator *v, 198 + static int sb_check(const struct dm_block_validator *v, 199 199 struct dm_block *b, 200 200 size_t sb_block_size) 201 201 { ··· 228 228 return check_metadata_version(disk_super); 229 229 } 230 230 231 - static struct dm_block_validator sb_validator = { 231 + static const struct dm_block_validator sb_validator = { 232 232 .name = "superblock", 233 233 .prepare_for_write = sb_prepare_for_write, 234 234 .check = sb_check
+3 -3
drivers/md/dm-clone-metadata.c
··· 163 163 /* 164 164 * Superblock validation. 165 165 */ 166 - static void sb_prepare_for_write(struct dm_block_validator *v, 166 + static void sb_prepare_for_write(const struct dm_block_validator *v, 167 167 struct dm_block *b, size_t sb_block_size) 168 168 { 169 169 struct superblock_disk *sb; ··· 177 177 sb->csum = cpu_to_le32(csum); 178 178 } 179 179 180 - static int sb_check(struct dm_block_validator *v, struct dm_block *b, 180 + static int sb_check(const struct dm_block_validator *v, struct dm_block *b, 181 181 size_t sb_block_size) 182 182 { 183 183 struct superblock_disk *sb; ··· 220 220 return 0; 221 221 } 222 222 223 - static struct dm_block_validator sb_validator = { 223 + static const struct dm_block_validator sb_validator = { 224 224 .name = "superblock", 225 225 .prepare_for_write = sb_prepare_for_write, 226 226 .check = sb_check
+3 -3
drivers/md/dm-era-target.c
··· 196 196 * Superblock validation 197 197 *-------------------------------------------------------------- 198 198 */ 199 - static void sb_prepare_for_write(struct dm_block_validator *v, 199 + static void sb_prepare_for_write(const struct dm_block_validator *v, 200 200 struct dm_block *b, 201 201 size_t sb_block_size) 202 202 { ··· 221 221 return 0; 222 222 } 223 223 224 - static int sb_check(struct dm_block_validator *v, 224 + static int sb_check(const struct dm_block_validator *v, 225 225 struct dm_block *b, 226 226 size_t sb_block_size) 227 227 { ··· 254 254 return check_metadata_version(disk); 255 255 } 256 256 257 - static struct dm_block_validator sb_validator = { 257 + static const struct dm_block_validator sb_validator = { 258 258 .name = "superblock", 259 259 .prepare_for_write = sb_prepare_for_write, 260 260 .check = sb_check
+3 -3
drivers/md/dm-thin-metadata.c
··· 249 249 */ 250 250 #define SUPERBLOCK_CSUM_XOR 160774 251 251 252 - static void sb_prepare_for_write(struct dm_block_validator *v, 252 + static void sb_prepare_for_write(const struct dm_block_validator *v, 253 253 struct dm_block *b, 254 254 size_t block_size) 255 255 { ··· 261 261 SUPERBLOCK_CSUM_XOR)); 262 262 } 263 263 264 - static int sb_check(struct dm_block_validator *v, 264 + static int sb_check(const struct dm_block_validator *v, 265 265 struct dm_block *b, 266 266 size_t block_size) 267 267 { ··· 294 294 return 0; 295 295 } 296 296 297 - static struct dm_block_validator sb_validator = { 297 + static const struct dm_block_validator sb_validator = { 298 298 .name = "superblock", 299 299 .prepare_for_write = sb_prepare_for_write, 300 300 .check = sb_check
+3 -3
drivers/md/persistent-data/dm-array.c
··· 38 38 */ 39 39 #define CSUM_XOR 595846735 40 40 41 - static void array_block_prepare_for_write(struct dm_block_validator *v, 41 + static void array_block_prepare_for_write(const struct dm_block_validator *v, 42 42 struct dm_block *b, 43 43 size_t size_of_block) 44 44 { ··· 50 50 CSUM_XOR)); 51 51 } 52 52 53 - static int array_block_check(struct dm_block_validator *v, 53 + static int array_block_check(const struct dm_block_validator *v, 54 54 struct dm_block *b, 55 55 size_t size_of_block) 56 56 { ··· 77 77 return 0; 78 78 } 79 79 80 - static struct dm_block_validator array_validator = { 80 + static const struct dm_block_validator array_validator = { 81 81 .name = "array", 82 82 .prepare_for_write = array_block_prepare_for_write, 83 83 .check = array_block_check
+6 -6
drivers/md/persistent-data/dm-block-manager.c
··· 345 345 EXPORT_SYMBOL_GPL(dm_block_data); 346 346 347 347 struct buffer_aux { 348 - struct dm_block_validator *validator; 348 + const struct dm_block_validator *validator; 349 349 int write_locked; 350 350 351 351 #ifdef CONFIG_DM_DEBUG_BLOCK_MANAGER_LOCKING ··· 441 441 static int dm_bm_validate_buffer(struct dm_block_manager *bm, 442 442 struct dm_buffer *buf, 443 443 struct buffer_aux *aux, 444 - struct dm_block_validator *v) 444 + const struct dm_block_validator *v) 445 445 { 446 446 if (unlikely(!aux->validator)) { 447 447 int r; ··· 467 467 return 0; 468 468 } 469 469 int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b, 470 - struct dm_block_validator *v, 470 + const struct dm_block_validator *v, 471 471 struct dm_block **result) 472 472 { 473 473 struct buffer_aux *aux; ··· 500 500 EXPORT_SYMBOL_GPL(dm_bm_read_lock); 501 501 502 502 int dm_bm_write_lock(struct dm_block_manager *bm, 503 - dm_block_t b, struct dm_block_validator *v, 503 + dm_block_t b, const struct dm_block_validator *v, 504 504 struct dm_block **result) 505 505 { 506 506 struct buffer_aux *aux; ··· 536 536 EXPORT_SYMBOL_GPL(dm_bm_write_lock); 537 537 538 538 int dm_bm_read_try_lock(struct dm_block_manager *bm, 539 - dm_block_t b, struct dm_block_validator *v, 539 + dm_block_t b, const struct dm_block_validator *v, 540 540 struct dm_block **result) 541 541 { 542 542 struct buffer_aux *aux; ··· 569 569 } 570 570 571 571 int dm_bm_write_lock_zero(struct dm_block_manager *bm, 572 - dm_block_t b, struct dm_block_validator *v, 572 + dm_block_t b, const struct dm_block_validator *v, 573 573 struct dm_block **result) 574 574 { 575 575 int r;
+8 -6
drivers/md/persistent-data/dm-block-manager.h
··· 51 51 */ 52 52 struct dm_block_validator { 53 53 const char *name; 54 - void (*prepare_for_write)(struct dm_block_validator *v, struct dm_block *b, size_t block_size); 54 + void (*prepare_for_write)(const struct dm_block_validator *v, 55 + struct dm_block *b, size_t block_size); 55 56 56 57 /* 57 58 * Return 0 if the checksum is valid or < 0 on error. 58 59 */ 59 - int (*check)(struct dm_block_validator *v, struct dm_block *b, size_t block_size); 60 + int (*check)(const struct dm_block_validator *v, 61 + struct dm_block *b, size_t block_size); 60 62 }; 61 63 62 64 /*----------------------------------------------------------------*/ ··· 75 73 * written back to the disk sometime after dm_bm_unlock is called. 76 74 */ 77 75 int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b, 78 - struct dm_block_validator *v, 76 + const struct dm_block_validator *v, 79 77 struct dm_block **result); 80 78 81 79 int dm_bm_write_lock(struct dm_block_manager *bm, dm_block_t b, 82 - struct dm_block_validator *v, 80 + const struct dm_block_validator *v, 83 81 struct dm_block **result); 84 82 85 83 /* ··· 87 85 * available immediately. 88 86 */ 89 87 int dm_bm_read_try_lock(struct dm_block_manager *bm, dm_block_t b, 90 - struct dm_block_validator *v, 88 + const struct dm_block_validator *v, 91 89 struct dm_block **result); 92 90 93 91 /* ··· 95 93 * overwrite the block completely. It saves a disk read. 96 94 */ 97 95 int dm_bm_write_lock_zero(struct dm_block_manager *bm, dm_block_t b, 98 - struct dm_block_validator *v, 96 + const struct dm_block_validator *v, 99 97 struct dm_block **result); 100 98 101 99 void dm_bm_unlock(struct dm_block *b);
+1 -1
drivers/md/persistent-data/dm-btree-internal.h
··· 138 138 */ 139 139 int lower_bound(struct btree_node *n, uint64_t key); 140 140 141 - extern struct dm_block_validator btree_node_validator; 141 + extern const struct dm_block_validator btree_node_validator; 142 142 143 143 /* 144 144 * Value type for upper levels of multi-level btrees.
+3 -3
drivers/md/persistent-data/dm-btree-spine.c
··· 16 16 17 17 #define BTREE_CSUM_XOR 121107 18 18 19 - static void node_prepare_for_write(struct dm_block_validator *v, 19 + static void node_prepare_for_write(const struct dm_block_validator *v, 20 20 struct dm_block *b, 21 21 size_t block_size) 22 22 { ··· 29 29 BTREE_CSUM_XOR)); 30 30 } 31 31 32 - static int node_check(struct dm_block_validator *v, 32 + static int node_check(const struct dm_block_validator *v, 33 33 struct dm_block *b, 34 34 size_t block_size) 35 35 { ··· 81 81 return 0; 82 82 } 83 83 84 - struct dm_block_validator btree_node_validator = { 84 + const struct dm_block_validator btree_node_validator = { 85 85 .name = "btree_node", 86 86 .prepare_for_write = node_prepare_for_write, 87 87 .check = node_check
+6 -6
drivers/md/persistent-data/dm-space-map-common.c
··· 22 22 */ 23 23 #define INDEX_CSUM_XOR 160478 24 24 25 - static void index_prepare_for_write(struct dm_block_validator *v, 25 + static void index_prepare_for_write(const struct dm_block_validator *v, 26 26 struct dm_block *b, 27 27 size_t block_size) 28 28 { ··· 34 34 INDEX_CSUM_XOR)); 35 35 } 36 36 37 - static int index_check(struct dm_block_validator *v, 37 + static int index_check(const struct dm_block_validator *v, 38 38 struct dm_block *b, 39 39 size_t block_size) 40 40 { ··· 59 59 return 0; 60 60 } 61 61 62 - static struct dm_block_validator index_validator = { 62 + static const struct dm_block_validator index_validator = { 63 63 .name = "index", 64 64 .prepare_for_write = index_prepare_for_write, 65 65 .check = index_check ··· 72 72 */ 73 73 #define BITMAP_CSUM_XOR 240779 74 74 75 - static void dm_bitmap_prepare_for_write(struct dm_block_validator *v, 75 + static void dm_bitmap_prepare_for_write(const struct dm_block_validator *v, 76 76 struct dm_block *b, 77 77 size_t block_size) 78 78 { ··· 84 84 BITMAP_CSUM_XOR)); 85 85 } 86 86 87 - static int dm_bitmap_check(struct dm_block_validator *v, 87 + static int dm_bitmap_check(const struct dm_block_validator *v, 88 88 struct dm_block *b, 89 89 size_t block_size) 90 90 { ··· 109 109 return 0; 110 110 } 111 111 112 - static struct dm_block_validator dm_sm_bitmap_validator = { 112 + static const struct dm_block_validator dm_sm_bitmap_validator = { 113 113 .name = "sm_bitmap", 114 114 .prepare_for_write = dm_bitmap_prepare_for_write, 115 115 .check = dm_bitmap_check,
+4 -4
drivers/md/persistent-data/dm-transaction-manager.c
··· 237 237 EXPORT_SYMBOL_GPL(dm_tm_commit); 238 238 239 239 int dm_tm_new_block(struct dm_transaction_manager *tm, 240 - struct dm_block_validator *v, 240 + const struct dm_block_validator *v, 241 241 struct dm_block **result) 242 242 { 243 243 int r; ··· 266 266 } 267 267 268 268 static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, 269 - struct dm_block_validator *v, 269 + const struct dm_block_validator *v, 270 270 struct dm_block **result) 271 271 { 272 272 int r; ··· 306 306 } 307 307 308 308 int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, 309 - struct dm_block_validator *v, struct dm_block **result, 309 + const struct dm_block_validator *v, struct dm_block **result, 310 310 int *inc_children) 311 311 { 312 312 int r; ··· 331 331 EXPORT_SYMBOL_GPL(dm_tm_shadow_block); 332 332 333 333 int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b, 334 - struct dm_block_validator *v, 334 + const struct dm_block_validator *v, 335 335 struct dm_block **blk) 336 336 { 337 337 if (tm->is_clone) {
+3 -3
drivers/md/persistent-data/dm-transaction-manager.h
··· 64 64 * Zeroes the new block and returns with write lock held. 65 65 */ 66 66 int dm_tm_new_block(struct dm_transaction_manager *tm, 67 - struct dm_block_validator *v, 67 + const struct dm_block_validator *v, 68 68 struct dm_block **result); 69 69 70 70 /* ··· 84 84 * it locked when you call this. 85 85 */ 86 86 int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, 87 - struct dm_block_validator *v, 87 + const struct dm_block_validator *v, 88 88 struct dm_block **result, int *inc_children); 89 89 90 90 /* ··· 92 92 * on it outstanding then it'll block. 93 93 */ 94 94 int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b, 95 - struct dm_block_validator *v, 95 + const struct dm_block_validator *v, 96 96 struct dm_block **result); 97 97 98 98 void dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b);