1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
#include "dm-verity-debug.h"
#include <linux/module.h>
#include <linux/reboot.h>
#include <linux/ctype.h>
#define DM_MSG_PREFIX "verity"
#define DM_VERITY_ENV_LENGTH 42
#define DM_VERITY_ENV_VAR_NAME "DM_VERITY_ERR_BLOCK_NR"
#define DM_VERITY_DEFAULT_PREFETCH_SIZE 262144
#define DM_VERITY_MAX_CORRUPTED_ERRS 100
struct blks_info* b_info = 0;
int empty_b_info(void){
return (b_info) ? 0 : 1;
}
struct blks_info * create_b_info(void){
b_info = kzalloc(sizeof(struct blks_info),GFP_KERNEL);
return b_info;
}
void free_b_info(void){
if(empty_b_info())
return;
kfree(b_info);
}
/* get */
long long get_total_blks(void){
if(!empty_b_info())
return atomic64_read(&b_info->total_blks);
return 0;
}
long long get_skipped_blks(void){
if(!empty_b_info())
return atomic64_read(&b_info->skipped_blks);
return 0;
}
long long get_fec_correct_blks(void){
if(!empty_b_info())
return atomic64_read(&b_info->fec_correct_blks);
return 0;
}
long long get_corrupted_blks(void){
if(!empty_b_info())
return atomic64_read(&b_info->corrupted_blks);
return 0;
}
long long get_prev_total_blks(void){
if(!empty_b_info())
return atomic64_read(&b_info->prev_total_blks);
return 0;
}
int get_fec_off_cnt(void){
if(!empty_b_info())
return atomic_read(&b_info->fec_off_cnt);
return 0;
}
int get_dmv_ctr_cnt(void){
if(!empty_b_info())
return atomic_read(&b_info->dmv_ctr_cnt);
return 0;
}
void add_dmv_ctr_entry(char* dev_name){
int idx = get_dmv_ctr_cnt();
if(!empty_b_info() && idx < MAX_DEV_LIST){
snprintf(b_info->dmv_ctr_list[idx],MAX_DEV_NAME,"%s",dev_name);
atomic_inc(&b_info->dmv_ctr_cnt);
}
}
struct blks_info * get_b_info(char* dev_name){
pr_err("dm-verity-debug : dev_name = %s\n",dev_name);
if(empty_b_info()){
b_info = create_b_info();
add_dmv_ctr_entry(dev_name);
}
else{
pr_info("dm-verity-debug : b_info already exists\n");
add_dmv_ctr_entry(dev_name);
return b_info;
}
if(!b_info){
pr_err("dm-verity-debug : Can't get b_info !\n");
return 0;
}
pr_info("dm-verity-debug : get b_info successfully\n");
return b_info;
}
/* set */
void set_prev_total_blks(long long val){
if(!empty_b_info())
atomic64_set(&b_info->prev_total_blks, val);
}
/* add */
void add_total_blks(long long val){
if(!empty_b_info())
atomic64_add(val, &b_info->total_blks);
}
void add_skipped_blks(void){
if(!empty_b_info())
atomic64_inc(&b_info->skipped_blks);
}
void add_fec_correct_blks(void){
if(!empty_b_info())
atomic64_inc(&b_info->fec_correct_blks);
}
void add_corrupted_blks(void){
if(!empty_b_info())
atomic64_inc(&b_info->corrupted_blks);
}
void add_fc_blks_entry(sector_t cur_blk, char* dev_name){
if(empty_b_info()){
pr_err("dm-verity-debug : b_info is empty !\n");
return;
}
b_info->fc_blks_list[b_info->list_idx] = cur_blk;
snprintf(b_info->dev_name[b_info->list_idx],MAX_DEV_NAME,"%s",dev_name);
b_info->list_idx = (b_info->list_idx + 1) % MAX_FC_BLKS_LIST;
}
void add_fec_off_cnt(char* dev_name){
if(!empty_b_info()){
int idx = get_fec_off_cnt();
if(idx < MAX_DEV_LIST){
snprintf(b_info->fec_off_list[idx],MAX_DEV_NAME,"%s",dev_name);
atomic_inc(&b_info->fec_off_cnt);
}
}
}
void print_blks_cnt(char* dev_name){
int i,foc = get_fec_off_cnt();
if(empty_b_info()){
return;
}
pr_err("dev_name = %s,total_blks = %llu,skipped_blks = %llu,corrupted_blks = %llu,fec_correct_blks = %llu",dev_name,get_total_blks(),get_skipped_blks(),get_corrupted_blks(),get_fec_correct_blks());
if(foc > 0){
pr_err("fec_off_cnt = %d",foc);
for(i = 0 ; i < foc; i++)
pr_err("fec_off_dev = %s ",b_info->fec_off_list[i]);
}
}
void print_fc_blks_list(void){
int i = 0;
if(empty_b_info()){
return;
}
if(get_fec_correct_blks() == 0)
return;
pr_err("\n====== FC_BLKS_LIST START ======\n");
if ((long long) MAX_FC_BLKS_LIST <= get_fec_correct_blks()){
pr_err("%s %llu",b_info->dev_name[b_info->list_idx],(unsigned long long)b_info->fc_blks_list[b_info->list_idx]);
i = (b_info->list_idx + 1) % MAX_FC_BLKS_LIST;
}
for( ; i != b_info->list_idx; i = (i + 1) % MAX_FC_BLKS_LIST)
pr_err("%s %llu",b_info->dev_name[i],(unsigned long long)b_info->fc_blks_list[i]);
pr_err("====== FC_BLKS_LIST END ======\n");
}
void print_dmv_ctr_list(void){
int i = 0, ctr_cnt = get_dmv_ctr_cnt();
if(empty_b_info()){
return;
}
pr_err("\n====== DMV_CTR_LIST START ======\n");
for( ; i < ctr_cnt; i++)
pr_err("%s",b_info->dmv_ctr_list[i]);
pr_err("====== DMV_CTR_LIST END ======\n");
}
static void print_block_data(unsigned long long blocknr, unsigned char *data_to_dump
, int start, int len)
{
int i, j;
int bh_offset = (start / 16) * 16;
char row_data[17] = { 0, };
char row_hex[50] = { 0, };
char ch;
if (blocknr == 0) {
pr_err("printing Hash dump %dbyte, hash_to_dump 0x%p\n", len, (void *)data_to_dump);
} else {
pr_err("dm-verity corrupted, printing data in hex\n");
pr_err(" dump block# : %llu, start offset(byte) : %d\n"
, blocknr, start);
pr_err(" length(byte) : %d, data_to_dump 0x%p\n"
, len, (void *)data_to_dump);
pr_err("-------------------------------------------------\n");
}
for (i = 0; i < (len + 15) / 16; i++) {
for (j = 0; j < 16; j++) {
ch = *(data_to_dump + bh_offset + j);
if (start <= bh_offset + j
&& start + len > bh_offset + j) {
if (isascii(ch) && isprint(ch))
sprintf(row_data + j, "%c", ch);
else
sprintf(row_data + j, ".");
sprintf(row_hex + (j * 3), "%2.2x ", ch);
} else {
sprintf(row_data + j, " ");
sprintf(row_hex + (j * 3), "-- ");
}
}
pr_err("0x%4.4x : %s | %s\n"
, bh_offset, row_hex, row_data);
bh_offset += 16;
}
pr_err("---------------------------------------------------\n");
}
int verity_handle_err_hex_debug(struct dm_verity *v, enum verity_block_type type,
unsigned long long block, struct dm_verity_io *io, struct bvec_iter *iter)
{
char verity_env[DM_VERITY_ENV_LENGTH];
char *envp[] = { verity_env, NULL };
const char *type_str = "";
struct dm_buffer *buf;
struct mapped_device *md = dm_table_get_md(v->ti->table);
struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size);
struct bio_vec bv;
u8 *data;
u8 *page;
int i;
char hex_str[65] = {0, };
/* Corruption should be visible in device status in all modes */
v->hash_failed = 1;
if (ignore_fs_panic) {
DMERR("%s: Don't trigger a panic during cleanup for shutdown. Skipping %s",
v->data_dev->name, __func__);
return 0;
}
if (block == 0) {
DMERR("%s: block 0 is superblock. Skipping %s", v->data_dev->name, __func__);
return 0;
}
if (v->corrupted_errs >= DM_VERITY_MAX_CORRUPTED_ERRS)
goto out;
v->corrupted_errs++;
switch (type) {
case DM_VERITY_BLOCK_TYPE_DATA:
type_str = "data";
break;
case DM_VERITY_BLOCK_TYPE_METADATA:
type_str = "metadata";
break;
default:
BUG();
}
if(empty_b_info()){
pr_err("dm-verity-debug : b_info is empty !\n");
}
else{
print_dmv_ctr_list();
print_blks_cnt(v->data_dev->name);
print_fc_blks_list();
}
DMERR("%s: %s block %llu is corrupted", v->data_dev->name, type_str, block);
for(i=0 ; i < v->salt_size; i++){
sprintf(hex_str + (i * 2), "%02x", *(v->salt + i));
}
DMERR("dm-verity salt: %s", hex_str);
if (!(strcmp(type_str, "metadata"))) {
data = dm_bufio_read(v->bufio, block, &buf);
print_block_data(0, (unsigned char *)(verity_io_real_digest(v, io)), 0, v->digest_size);
print_block_data(0, (unsigned char *)(verity_io_want_digest(v, io)), 0, v->digest_size);
print_block_data((unsigned long long)block, (unsigned char *)data, 0, PAGE_SIZE);
} else if (!(strcmp(type_str, "data"))) {
bv = bio_iter_iovec(bio, *iter);
page = kmap_atomic(bv.bv_page);
print_block_data(0, (unsigned char *)(verity_io_real_digest(v, io)), 0, v->digest_size);
print_block_data(0, (unsigned char *)(verity_io_want_digest(v, io)), 0, v->digest_size);
print_block_data((unsigned long long)block, (unsigned char *)page, 0, PAGE_SIZE);
kunmap_atomic(page);
} else {
DMERR("%s: %s block : Unknown block type", v->data_dev->name, type_str);
}
#ifdef DMV_ALTA
if (io->io_retry == IO_RETRY_MAX) panic("dmv corrupt");
#else
panic("dmv corrupt");
#endif
if (v->corrupted_errs == DM_VERITY_MAX_CORRUPTED_ERRS)
DMERR("%s: reached maximum errors", v->data_dev->name);
snprintf(verity_env, DM_VERITY_ENV_LENGTH, "%s=%d,%llu",
DM_VERITY_ENV_VAR_NAME, type, block);
kobject_uevent_env(&disk_to_dev(dm_disk(md))->kobj, KOBJ_CHANGE, envp);
out:
if (v->mode == DM_VERITY_MODE_LOGGING)
return 0;
if (v->mode == DM_VERITY_MODE_RESTART)
kernel_restart("dm-verity device corrupted");
return 1;
}
|