Skip to content

Commit 0b60be1

Browse files
tititiou36Mikulas Patocka
authored andcommitted
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 <[email protected]> Signed-off-by: Mikulas Patocka <[email protected]>
1 parent fb09876 commit 0b60be1

12 files changed

+46
-44
lines changed

drivers/md/dm-cache-metadata.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ struct dm_cache_metadata {
170170
*/
171171
#define SUPERBLOCK_CSUM_XOR 9031977
172172

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,
174174
struct dm_block *b,
175175
size_t sb_block_size)
176176
{
@@ -195,7 +195,7 @@ static int check_metadata_version(struct cache_disk_superblock *disk_super)
195195
return 0;
196196
}
197197

198-
static int sb_check(struct dm_block_validator *v,
198+
static int sb_check(const struct dm_block_validator *v,
199199
struct dm_block *b,
200200
size_t sb_block_size)
201201
{
@@ -228,7 +228,7 @@ static int sb_check(struct dm_block_validator *v,
228228
return check_metadata_version(disk_super);
229229
}
230230

231-
static struct dm_block_validator sb_validator = {
231+
static const struct dm_block_validator sb_validator = {
232232
.name = "superblock",
233233
.prepare_for_write = sb_prepare_for_write,
234234
.check = sb_check

drivers/md/dm-clone-metadata.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ struct dm_clone_metadata {
163163
/*
164164
* Superblock validation.
165165
*/
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,
167167
struct dm_block *b, size_t sb_block_size)
168168
{
169169
struct superblock_disk *sb;
@@ -177,7 +177,7 @@ static void sb_prepare_for_write(struct dm_block_validator *v,
177177
sb->csum = cpu_to_le32(csum);
178178
}
179179

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,
181181
size_t sb_block_size)
182182
{
183183
struct superblock_disk *sb;
@@ -220,7 +220,7 @@ static int sb_check(struct dm_block_validator *v, struct dm_block *b,
220220
return 0;
221221
}
222222

223-
static struct dm_block_validator sb_validator = {
223+
static const struct dm_block_validator sb_validator = {
224224
.name = "superblock",
225225
.prepare_for_write = sb_prepare_for_write,
226226
.check = sb_check

drivers/md/dm-era-target.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ struct superblock_disk {
196196
* Superblock validation
197197
*--------------------------------------------------------------
198198
*/
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,
200200
struct dm_block *b,
201201
size_t sb_block_size)
202202
{
@@ -221,7 +221,7 @@ static int check_metadata_version(struct superblock_disk *disk)
221221
return 0;
222222
}
223223

224-
static int sb_check(struct dm_block_validator *v,
224+
static int sb_check(const struct dm_block_validator *v,
225225
struct dm_block *b,
226226
size_t sb_block_size)
227227
{
@@ -254,7 +254,7 @@ static int sb_check(struct dm_block_validator *v,
254254
return check_metadata_version(disk);
255255
}
256256

257-
static struct dm_block_validator sb_validator = {
257+
static const struct dm_block_validator sb_validator = {
258258
.name = "superblock",
259259
.prepare_for_write = sb_prepare_for_write,
260260
.check = sb_check

drivers/md/dm-thin-metadata.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ struct dm_thin_device {
249249
*/
250250
#define SUPERBLOCK_CSUM_XOR 160774
251251

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,
253253
struct dm_block *b,
254254
size_t block_size)
255255
{
@@ -261,7 +261,7 @@ static void sb_prepare_for_write(struct dm_block_validator *v,
261261
SUPERBLOCK_CSUM_XOR));
262262
}
263263

264-
static int sb_check(struct dm_block_validator *v,
264+
static int sb_check(const struct dm_block_validator *v,
265265
struct dm_block *b,
266266
size_t block_size)
267267
{
@@ -294,7 +294,7 @@ static int sb_check(struct dm_block_validator *v,
294294
return 0;
295295
}
296296

297-
static struct dm_block_validator sb_validator = {
297+
static const struct dm_block_validator sb_validator = {
298298
.name = "superblock",
299299
.prepare_for_write = sb_prepare_for_write,
300300
.check = sb_check

drivers/md/persistent-data/dm-array.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct array_block {
3838
*/
3939
#define CSUM_XOR 595846735
4040

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,
4242
struct dm_block *b,
4343
size_t size_of_block)
4444
{
@@ -50,7 +50,7 @@ static void array_block_prepare_for_write(struct dm_block_validator *v,
5050
CSUM_XOR));
5151
}
5252

53-
static int array_block_check(struct dm_block_validator *v,
53+
static int array_block_check(const struct dm_block_validator *v,
5454
struct dm_block *b,
5555
size_t size_of_block)
5656
{
@@ -77,7 +77,7 @@ static int array_block_check(struct dm_block_validator *v,
7777
return 0;
7878
}
7979

80-
static struct dm_block_validator array_validator = {
80+
static const struct dm_block_validator array_validator = {
8181
.name = "array",
8282
.prepare_for_write = array_block_prepare_for_write,
8383
.check = array_block_check

drivers/md/persistent-data/dm-block-manager.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ void *dm_block_data(struct dm_block *b)
345345
EXPORT_SYMBOL_GPL(dm_block_data);
346346

347347
struct buffer_aux {
348-
struct dm_block_validator *validator;
348+
const struct dm_block_validator *validator;
349349
int write_locked;
350350

351351
#ifdef CONFIG_DM_DEBUG_BLOCK_MANAGER_LOCKING
@@ -441,7 +441,7 @@ dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm)
441441
static int dm_bm_validate_buffer(struct dm_block_manager *bm,
442442
struct dm_buffer *buf,
443443
struct buffer_aux *aux,
444-
struct dm_block_validator *v)
444+
const struct dm_block_validator *v)
445445
{
446446
if (unlikely(!aux->validator)) {
447447
int r;
@@ -467,7 +467,7 @@ static int dm_bm_validate_buffer(struct dm_block_manager *bm,
467467
return 0;
468468
}
469469
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,
471471
struct dm_block **result)
472472
{
473473
struct buffer_aux *aux;
@@ -500,7 +500,7 @@ int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
500500
EXPORT_SYMBOL_GPL(dm_bm_read_lock);
501501

502502
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,
504504
struct dm_block **result)
505505
{
506506
struct buffer_aux *aux;
@@ -536,7 +536,7 @@ int dm_bm_write_lock(struct dm_block_manager *bm,
536536
EXPORT_SYMBOL_GPL(dm_bm_write_lock);
537537

538538
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,
540540
struct dm_block **result)
541541
{
542542
struct buffer_aux *aux;
@@ -569,7 +569,7 @@ int dm_bm_read_try_lock(struct dm_block_manager *bm,
569569
}
570570

571571
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,
573573
struct dm_block **result)
574574
{
575575
int r;

drivers/md/persistent-data/dm-block-manager.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm);
5151
*/
5252
struct dm_block_validator {
5353
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);
5556

5657
/*
5758
* Return 0 if the checksum is valid or < 0 on error.
5859
*/
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);
6062
};
6163

6264
/*----------------------------------------------------------------*/
@@ -73,27 +75,27 @@ struct dm_block_validator {
7375
* written back to the disk sometime after dm_bm_unlock is called.
7476
*/
7577
int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
76-
struct dm_block_validator *v,
78+
const struct dm_block_validator *v,
7779
struct dm_block **result);
7880

7981
int dm_bm_write_lock(struct dm_block_manager *bm, dm_block_t b,
80-
struct dm_block_validator *v,
82+
const struct dm_block_validator *v,
8183
struct dm_block **result);
8284

8385
/*
8486
* The *_try_lock variants return -EWOULDBLOCK if the block isn't
8587
* available immediately.
8688
*/
8789
int dm_bm_read_try_lock(struct dm_block_manager *bm, dm_block_t b,
88-
struct dm_block_validator *v,
90+
const struct dm_block_validator *v,
8991
struct dm_block **result);
9092

9193
/*
9294
* Use dm_bm_write_lock_zero() when you know you're going to
9395
* overwrite the block completely. It saves a disk read.
9496
*/
9597
int dm_bm_write_lock_zero(struct dm_block_manager *bm, dm_block_t b,
96-
struct dm_block_validator *v,
98+
const struct dm_block_validator *v,
9799
struct dm_block **result);
98100

99101
void dm_bm_unlock(struct dm_block *b);

drivers/md/persistent-data/dm-btree-internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static inline uint64_t value64(struct btree_node *n, uint32_t index)
138138
*/
139139
int lower_bound(struct btree_node *n, uint64_t key);
140140

141-
extern struct dm_block_validator btree_node_validator;
141+
extern const struct dm_block_validator btree_node_validator;
142142

143143
/*
144144
* Value type for upper levels of multi-level btrees.

drivers/md/persistent-data/dm-btree-spine.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#define BTREE_CSUM_XOR 121107
1818

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,
2020
struct dm_block *b,
2121
size_t block_size)
2222
{
@@ -29,7 +29,7 @@ static void node_prepare_for_write(struct dm_block_validator *v,
2929
BTREE_CSUM_XOR));
3030
}
3131

32-
static int node_check(struct dm_block_validator *v,
32+
static int node_check(const struct dm_block_validator *v,
3333
struct dm_block *b,
3434
size_t block_size)
3535
{
@@ -81,7 +81,7 @@ static int node_check(struct dm_block_validator *v,
8181
return 0;
8282
}
8383

84-
struct dm_block_validator btree_node_validator = {
84+
const struct dm_block_validator btree_node_validator = {
8585
.name = "btree_node",
8686
.prepare_for_write = node_prepare_for_write,
8787
.check = node_check

drivers/md/persistent-data/dm-space-map-common.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
#define INDEX_CSUM_XOR 160478
2424

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,
2626
struct dm_block *b,
2727
size_t block_size)
2828
{
@@ -34,7 +34,7 @@ static void index_prepare_for_write(struct dm_block_validator *v,
3434
INDEX_CSUM_XOR));
3535
}
3636

37-
static int index_check(struct dm_block_validator *v,
37+
static int index_check(const struct dm_block_validator *v,
3838
struct dm_block *b,
3939
size_t block_size)
4040
{
@@ -59,7 +59,7 @@ static int index_check(struct dm_block_validator *v,
5959
return 0;
6060
}
6161

62-
static struct dm_block_validator index_validator = {
62+
static const struct dm_block_validator index_validator = {
6363
.name = "index",
6464
.prepare_for_write = index_prepare_for_write,
6565
.check = index_check
@@ -72,7 +72,7 @@ static struct dm_block_validator index_validator = {
7272
*/
7373
#define BITMAP_CSUM_XOR 240779
7474

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,
7676
struct dm_block *b,
7777
size_t block_size)
7878
{
@@ -84,7 +84,7 @@ static void dm_bitmap_prepare_for_write(struct dm_block_validator *v,
8484
BITMAP_CSUM_XOR));
8585
}
8686

87-
static int dm_bitmap_check(struct dm_block_validator *v,
87+
static int dm_bitmap_check(const struct dm_block_validator *v,
8888
struct dm_block *b,
8989
size_t block_size)
9090
{
@@ -109,7 +109,7 @@ static int dm_bitmap_check(struct dm_block_validator *v,
109109
return 0;
110110
}
111111

112-
static struct dm_block_validator dm_sm_bitmap_validator = {
112+
static const struct dm_block_validator dm_sm_bitmap_validator = {
113113
.name = "sm_bitmap",
114114
.prepare_for_write = dm_bitmap_prepare_for_write,
115115
.check = dm_bitmap_check,

0 commit comments

Comments
 (0)