Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: dm-bht_unittest.cc

Issue 6851023: verity: don't call page_address on unmapped highmem pages (Closed) Base URL: http://git.chromium.org/git/dm-verity.git@master
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dm-bht.c ('k') | include/linux/mm_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (C) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (C) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by the GPL v2 license that can 2 // Use of this source code is governed by the GPL v2 license that can
3 // be found in the LICENSE file. 3 // be found in the LICENSE file.
4 // 4 //
5 // Basic unittesting of dm-bht using google-gtest. 5 // Basic unittesting of dm-bht using google-gtest.
6 6
7 #include <base/basictypes.h> 7 #include <base/basictypes.h>
8 #include <base/logging.h> 8 #include <base/logging.h>
9 #include <base/scoped_ptr.h> 9 #include <base/scoped_ptr.h>
10 #include <gtest/gtest.h> 10 #include <gtest/gtest.h>
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); 165 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE);
166 166
167 memset(zero_page, 0, PAGE_SIZE); 167 memset(zero_page, 0, PAGE_SIZE);
168 168
169 SetupBht(total_blocks, "sha256"); 169 SetupBht(total_blocks, "sha256");
170 dm_bht_set_root_hexdigest(bht_.get(), 170 dm_bht_set_root_hexdigest(bht_.get(),
171 reinterpret_cast<const u8 *>(kRootDigest)); 171 reinterpret_cast<const u8 *>(kRootDigest));
172 172
173 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) { 173 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) {
174 DLOG(INFO) << "verifying block: " << blocks; 174 DLOG(INFO) << "verifying block: " << blocks;
175 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks, zero_page)); 175 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks,
176 virt_to_page(zero_page), 0));
176 } 177 }
177 178
178 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); 179 EXPECT_EQ(0, dm_bht_destroy(bht_.get()));
179 free(zero_page); 180 free(zero_page);
180 } 181 }
181 182
182 TEST_F(MemoryBhtTest, CreateThenVerifySingleLevel) { 183 TEST_F(MemoryBhtTest, CreateThenVerifySingleLevel) {
183 static const unsigned int total_blocks = 32; 184 static const unsigned int total_blocks = 32;
184 // Set the root hash for a 0-filled image 185 // Set the root hash for a 0-filled image
185 static const char kRootDigest[] = 186 static const char kRootDigest[] =
186 "2d3a43008286f56536fa24dcdbf14d342f0548827e374210415c7be0b610d2ba"; 187 "2d3a43008286f56536fa24dcdbf14d342f0548827e374210415c7be0b610d2ba";
187 // A page of all zeros 188 // A page of all zeros
188 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); 189 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE);
189 190
190 memset(zero_page, 0, PAGE_SIZE); 191 memset(zero_page, 0, PAGE_SIZE);
191 192
192 SetupBht(total_blocks, "sha256"); 193 SetupBht(total_blocks, "sha256");
193 dm_bht_set_root_hexdigest(bht_.get(), 194 dm_bht_set_root_hexdigest(bht_.get(),
194 reinterpret_cast<const u8 *>(kRootDigest)); 195 reinterpret_cast<const u8 *>(kRootDigest));
195 196
196 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) { 197 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) {
197 DLOG(INFO) << "verifying block: " << blocks; 198 DLOG(INFO) << "verifying block: " << blocks;
198 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks, zero_page)); 199 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks,
200 virt_to_page(zero_page), 0));
199 } 201 }
200 202
201 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); 203 EXPECT_EQ(0, dm_bht_destroy(bht_.get()));
202 free(zero_page); 204 free(zero_page);
203 } 205 }
204 206
205 TEST_F(MemoryBhtTest, CreateThenVerifyRealParameters) { 207 TEST_F(MemoryBhtTest, CreateThenVerifyRealParameters) {
206 static const unsigned int total_blocks = 217600; 208 static const unsigned int total_blocks = 217600;
207 // Set the root hash for a 0-filled image 209 // Set the root hash for a 0-filled image
208 static const char kRootDigest[] = 210 static const char kRootDigest[] =
209 "15d5a180b5080a1d43e3fbd1f2cd021d0fc3ea91a8e330bad468b980c2fd4d8b"; 211 "15d5a180b5080a1d43e3fbd1f2cd021d0fc3ea91a8e330bad468b980c2fd4d8b";
210 // A page of all zeros 212 // A page of all zeros
211 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); 213 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE);
212 214
213 memset(zero_page, 0, PAGE_SIZE); 215 memset(zero_page, 0, PAGE_SIZE);
214 216
215 SetupBht(total_blocks, "sha256"); 217 SetupBht(total_blocks, "sha256");
216 dm_bht_set_root_hexdigest(bht_.get(), 218 dm_bht_set_root_hexdigest(bht_.get(),
217 reinterpret_cast<const u8 *>(kRootDigest)); 219 reinterpret_cast<const u8 *>(kRootDigest));
218 220
219 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) { 221 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) {
220 DLOG(INFO) << "verifying block: " << blocks; 222 DLOG(INFO) << "verifying block: " << blocks;
221 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks, zero_page)); 223 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks,
224 virt_to_page(zero_page), 0));
222 } 225 }
223 226
224 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); 227 EXPECT_EQ(0, dm_bht_destroy(bht_.get()));
225 free(zero_page); 228 free(zero_page);
226 } 229 }
227 230
228 TEST_F(MemoryBhtTest, CreateThenVerifyOddLeafCount) { 231 TEST_F(MemoryBhtTest, CreateThenVerifyOddLeafCount) {
229 static const unsigned int total_blocks = 16383; 232 static const unsigned int total_blocks = 16383;
230 // Set the root hash for a 0-filled image 233 // Set the root hash for a 0-filled image
231 static const char kRootDigest[] = 234 static const char kRootDigest[] =
232 "dc8cec4220d388b05ba75c853f858bb8cc25edfb1d5d2f3be6bdf9edfa66dc6a"; 235 "dc8cec4220d388b05ba75c853f858bb8cc25edfb1d5d2f3be6bdf9edfa66dc6a";
233 // A page of all zeros 236 // A page of all zeros
234 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); 237 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE);
235 238
236 memset(zero_page, 0, PAGE_SIZE); 239 memset(zero_page, 0, PAGE_SIZE);
237 240
238 SetupBht(total_blocks, "sha256"); 241 SetupBht(total_blocks, "sha256");
239 dm_bht_set_root_hexdigest(bht_.get(), 242 dm_bht_set_root_hexdigest(bht_.get(),
240 reinterpret_cast<const u8 *>(kRootDigest)); 243 reinterpret_cast<const u8 *>(kRootDigest));
241 244
242 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) { 245 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) {
243 DLOG(INFO) << "verifying block: " << blocks; 246 DLOG(INFO) << "verifying block: " << blocks;
244 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks, zero_page)); 247 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks,
248 virt_to_page(zero_page), 0));
245 } 249 }
246 250
247 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); 251 EXPECT_EQ(0, dm_bht_destroy(bht_.get()));
248 free(zero_page); 252 free(zero_page);
249 } 253 }
250 254
251 TEST_F(MemoryBhtTest, CreateThenVerifyOddNodeCount) { 255 TEST_F(MemoryBhtTest, CreateThenVerifyOddNodeCount) {
252 static const unsigned int total_blocks = 16000; 256 static const unsigned int total_blocks = 16000;
253 // Set the root hash for a 0-filled image 257 // Set the root hash for a 0-filled image
254 static const char kRootDigest[] = 258 static const char kRootDigest[] =
255 "10832dd62c427bcf68c56c8de0d1f9c32b61d9e5ddf43c77c56a97b372ad4b07"; 259 "10832dd62c427bcf68c56c8de0d1f9c32b61d9e5ddf43c77c56a97b372ad4b07";
256 // A page of all zeros 260 // A page of all zeros
257 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); 261 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE);
258 262
259 memset(zero_page, 0, PAGE_SIZE); 263 memset(zero_page, 0, PAGE_SIZE);
260 264
261 SetupBht(total_blocks, "sha256"); 265 SetupBht(total_blocks, "sha256");
262 dm_bht_set_root_hexdigest(bht_.get(), 266 dm_bht_set_root_hexdigest(bht_.get(),
263 reinterpret_cast<const u8 *>(kRootDigest)); 267 reinterpret_cast<const u8 *>(kRootDigest));
264 268
265 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) { 269 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) {
266 DLOG(INFO) << "verifying block: " << blocks; 270 DLOG(INFO) << "verifying block: " << blocks;
267 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks, zero_page)); 271 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks,
272 virt_to_page(zero_page), 0));
268 } 273 }
269 274
270 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); 275 EXPECT_EQ(0, dm_bht_destroy(bht_.get()));
271 free(zero_page); 276 free(zero_page);
272 } 277 }
273 278
274 TEST_F(MemoryBhtTest, CreateThenVerifyBadHashBlock) { 279 TEST_F(MemoryBhtTest, CreateThenVerifyBadHashBlock) {
275 static const unsigned int total_blocks = 16384; 280 static const unsigned int total_blocks = 16384;
276 // Set the root hash for a 0-filled image 281 // Set the root hash for a 0-filled image
277 static const char kRootDigest[] = 282 static const char kRootDigest[] =
(...skipping 10 matching lines...) Expand all
288 293
289 // TODO(wad) add tests for partial tree validity/verification 294 // TODO(wad) add tests for partial tree validity/verification
290 295
291 // Corrupt one has hblock 296 // Corrupt one has hblock
292 static const unsigned int kBadBlock = 256; 297 static const unsigned int kBadBlock = 256;
293 u8 *bad_hash_block= (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); 298 u8 *bad_hash_block= (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE);
294 memset(bad_hash_block, 'A', PAGE_SIZE); 299 memset(bad_hash_block, 'A', PAGE_SIZE);
295 EXPECT_EQ(dm_bht_store_block(bht_.get(), kBadBlock, bad_hash_block), 0); 300 EXPECT_EQ(dm_bht_store_block(bht_.get(), kBadBlock, bad_hash_block), 0);
296 301
297 // Attempt to verify both the bad block and all the neighbors. 302 // Attempt to verify both the bad block and all the neighbors.
298 EXPECT_LT(dm_bht_verify_block(bht_.get(), kBadBlock + 1, zero_page), 0); 303 EXPECT_LT(dm_bht_verify_block(bht_.get(), kBadBlock + 1,
304 virt_to_page(zero_page), 0), 0);
299 305
300 EXPECT_LT(dm_bht_verify_block(bht_.get(), kBadBlock + 2, zero_page), 0); 306 EXPECT_LT(dm_bht_verify_block(bht_.get(), kBadBlock + 2,
307 virt_to_page(zero_page), 0), 0);
301 308
302 EXPECT_LT(dm_bht_verify_block(bht_.get(), kBadBlock + (bht_->node_count / 2), 309 EXPECT_LT(dm_bht_verify_block(bht_.get(), kBadBlock + (bht_->node_count / 2),
303 zero_page), 310 virt_to_page(zero_page), 0), 0);
304 0);
305 311
306 EXPECT_LT(dm_bht_verify_block(bht_.get(), kBadBlock, zero_page), 0); 312 EXPECT_LT(dm_bht_verify_block(bht_.get(), kBadBlock,
313 virt_to_page(zero_page), 0), 0);
307 314
308 // Verify that the prior entry is untouched and still safe 315 // Verify that the prior entry is untouched and still safe
309 EXPECT_EQ(dm_bht_verify_block(bht_.get(), kBadBlock - 1, zero_page), 0); 316 EXPECT_EQ(dm_bht_verify_block(bht_.get(), kBadBlock - 1,
317 virt_to_page(zero_page), 0), 0);
310 318
311 // Same for the next entry 319 // Same for the next entry
312 EXPECT_EQ(dm_bht_verify_block(bht_.get(), kBadBlock + bht_->node_count, 320 EXPECT_EQ(dm_bht_verify_block(bht_.get(), kBadBlock + bht_->node_count,
313 zero_page), 321 virt_to_page(zero_page), 0), 0);
314 0);
315 322
316 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); 323 EXPECT_EQ(0, dm_bht_destroy(bht_.get()));
317 free(bad_hash_block); 324 free(bad_hash_block);
318 free(zero_page); 325 free(zero_page);
319 } 326 }
320 327
321 TEST_F(MemoryBhtTest, CreateThenVerifyBadDataBlock) { 328 TEST_F(MemoryBhtTest, CreateThenVerifyBadDataBlock) {
322 static const unsigned int total_blocks = 384; 329 static const unsigned int total_blocks = 384;
323 SetupBht(total_blocks, "sha256"); 330 SetupBht(total_blocks, "sha256");
324 // Set the root hash for a 0-filled image 331 // Set the root hash for a 0-filled image
325 static const char kRootDigest[] = 332 static const char kRootDigest[] =
326 "45d65d6f9e5a962f4d80b5f1bd7a918152251c27bdad8c5f52b590c129833372"; 333 "45d65d6f9e5a962f4d80b5f1bd7a918152251c27bdad8c5f52b590c129833372";
327 dm_bht_set_root_hexdigest(bht_.get(), 334 dm_bht_set_root_hexdigest(bht_.get(),
328 reinterpret_cast<const u8 *>(kRootDigest)); 335 reinterpret_cast<const u8 *>(kRootDigest));
329 // A corrupt page 336 // A corrupt page
330 u8 *bad_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); 337 u8 *bad_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE);
331 338
332 memset(bad_page, 'A', PAGE_SIZE); 339 memset(bad_page, 'A', PAGE_SIZE);
333 340
334 341
335 EXPECT_LT(dm_bht_verify_block(bht_.get(), 0, bad_page), 0); 342 EXPECT_LT(dm_bht_verify_block(bht_.get(), 0, virt_to_page(bad_page), 0), 0);
336 EXPECT_LT(dm_bht_verify_block(bht_.get(), 127, bad_page), 0); 343 EXPECT_LT(dm_bht_verify_block(bht_.get(), 127, virt_to_page(bad_page), 0), 0);
337 EXPECT_LT(dm_bht_verify_block(bht_.get(), 128, bad_page), 0); 344 EXPECT_LT(dm_bht_verify_block(bht_.get(), 128, virt_to_page(bad_page), 0), 0);
338 EXPECT_LT(dm_bht_verify_block(bht_.get(), 255, bad_page), 0); 345 EXPECT_LT(dm_bht_verify_block(bht_.get(), 255, virt_to_page(bad_page), 0), 0);
339 EXPECT_LT(dm_bht_verify_block(bht_.get(), 256, bad_page), 0); 346 EXPECT_LT(dm_bht_verify_block(bht_.get(), 256, virt_to_page(bad_page), 0), 0);
340 EXPECT_LT(dm_bht_verify_block(bht_.get(), 383, bad_page), 0); 347 EXPECT_LT(dm_bht_verify_block(bht_.get(), 383, virt_to_page(bad_page), 0), 0);
341 348
342 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); 349 EXPECT_EQ(0, dm_bht_destroy(bht_.get()));
343 free(bad_page); 350 free(bad_page);
344 } 351 }
OLDNEW
« no previous file with comments | « dm-bht.c ('k') | include/linux/mm_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698