github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/pkg/email/patch_test.go (about) 1 // Copyright 2017 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package email 5 6 import ( 7 "testing" 8 ) 9 10 func TestParsePatch(t *testing.T) { 11 for _, test := range tests { 12 t.Run(test.title, func(t *testing.T) { 13 diff := ParsePatch([]byte(test.text)) 14 if test.diff != diff { 15 t.Fatalf("diff mismatch, want:\n%v\ngot:\n%v", test.diff, diff) 16 } 17 }) 18 } 19 } 20 21 var tests = []struct { 22 text string 23 title string 24 diff string 25 }{ 26 { 27 text: ` 28 So that's my patch 29 diff --git a/foo/bar/foobar.c b/foo/bar/foobar.c 30 --- a/foo/bar/foobar.c 31 +++ b/foo/bar/foobar.c 32 @@ -2,7 +2,7 @@ 33 u32 chars = len; 34 int not_chars; 35 36 - if (!len) 37 + if (!len || !ln) 38 return 1; 39 40 return 0; 41 42 Watch out for the empty lines! 43 `, 44 title: ``, 45 diff: `diff --git a/foo/bar/foobar.c b/foo/bar/foobar.c 46 --- a/foo/bar/foobar.c 47 +++ b/foo/bar/foobar.c 48 @@ -2,7 +2,7 @@ 49 u32 chars = len; 50 int not_chars; 51 52 - if (!len) 53 + if (!len || !ln) 54 return 1; 55 56 return 0; 57 58 `, 59 }, 60 { 61 text: ` 62 commit 7bdb59aaaaaa4bd7161adc8f923cdef10f2638d1 63 Author: Some foo-bar áš <foo@bar.com> 64 Date: Tue Feb 7 17:44:54 2017 +0100 65 66 net/tcp: fix foo() 67 68 foo->bar is wrong. 69 Fix foo(). 70 71 More description. 72 73 Signed-off-by: Some foo-bar áš <foo@bar.com> 74 Reviewed: Some foo-bar <foo@bar.com> 75 Link: http://lkml.kernel.org/r/123123123123-123-1-git-send-email-foo@bar.com 76 77 diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c 78 index 74e0388cc88d..fc6f740d0277 100644 79 --- a/kernel/time/tick-sched.c 80 +++ b/kernel/time/tick-sched.c 81 @@ -725,6 +725,11 @@ static ktime_t tick_nohz_stop_sched_tick(struct tick_sched *ts, 82 */ 83 if (delta == 0) { 84 tick_nohz_restart(ts, now); 85 + /* 86 + * Make sure next tick stop doesn't get fooled by past 87 + * clock deadline 88 + */ 89 + ts->next_tick = 0; 90 goto out; 91 } 92 } 93 `, 94 title: "net/tcp: fix foo()", 95 diff: `diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c 96 index 74e0388cc88d..fc6f740d0277 100644 97 --- a/kernel/time/tick-sched.c 98 +++ b/kernel/time/tick-sched.c 99 @@ -725,6 +725,11 @@ static ktime_t tick_nohz_stop_sched_tick(struct tick_sched *ts, 100 */ 101 if (delta == 0) { 102 tick_nohz_restart(ts, now); 103 + /* 104 + * Make sure next tick stop doesn't get fooled by past 105 + * clock deadline 106 + */ 107 + ts->next_tick = 0; 108 goto out; 109 } 110 } 111 `, 112 }, 113 114 { 115 text: ` 116 fix looking up invalid subclass: 4294967295 117 118 diff --git a/net/irda/irqueue.c b/net/irda/irqueue.c 119 index acbe61c..160dc89 100644 120 --- a/net/irda/irqueue.c 121 +++ b/net/irda/irqueue.c 122 @@ -383,9 +383,6 @@ EXPORT_SYMBOL(hashbin_new); 123 * for deallocating this structure if it's complex. If not the user can 124 * just supply kfree, which should take care of the job. 125 */ 126 -#ifdef CONFIG_LOCKDEP 127 -static int hashbin_lock_depth = 0; 128 -#endif 129 int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func) 130 { 131 irda_queue_t* queue; 132 `, 133 title: "fix looking up invalid subclass: 4294967295", 134 diff: `diff --git a/net/irda/irqueue.c b/net/irda/irqueue.c 135 index acbe61c..160dc89 100644 136 --- a/net/irda/irqueue.c 137 +++ b/net/irda/irqueue.c 138 @@ -383,9 +383,6 @@ EXPORT_SYMBOL(hashbin_new); 139 * for deallocating this structure if it's complex. If not the user can 140 * just supply kfree, which should take care of the job. 141 */ 142 -#ifdef CONFIG_LOCKDEP 143 -static int hashbin_lock_depth = 0; 144 -#endif 145 int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func) 146 { 147 irda_queue_t* queue; 148 `, 149 }, 150 151 { 152 text: `net: fix looking up invalid subclass: 4294967295 153 diff --git a/net/irda/irqueue.c b/net/irda/irqueue.c 154 index acbe61c..160dc89 100644 155 --- a/net/irda/irqueue.c 156 +++ b/net/irda/irqueue.c 157 @@ -383,9 +383,6 @@ EXPORT_SYMBOL(hashbin_new); 158 * for deallocating this structure if it's complex. If not the user can 159 * just supply kfree, which should take care of the job. 160 */ 161 -#ifdef CONFIG_LOCKDEP 162 -static int hashbin_lock_depth = 0; 163 -#endif 164 int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func)`, 165 title: "net: fix looking up invalid subclass: 4294967295", 166 diff: `diff --git a/net/irda/irqueue.c b/net/irda/irqueue.c 167 index acbe61c..160dc89 100644 168 --- a/net/irda/irqueue.c 169 +++ b/net/irda/irqueue.c 170 @@ -383,9 +383,6 @@ EXPORT_SYMBOL(hashbin_new); 171 * for deallocating this structure if it's complex. If not the user can 172 * just supply kfree, which should take care of the job. 173 */ 174 -#ifdef CONFIG_LOCKDEP 175 -static int hashbin_lock_depth = 0; 176 -#endif 177 int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func) 178 `, 179 }, 180 181 { 182 text: ` 183 Delivered-To: foo@bar.com 184 Date: Tue, 31 Jan 2017 15:24:03 +0100 (CET) 185 To: Foo Bar <foo@bar.com> 186 Subject: [PATCH v2] timerfd: Protect the might cancel mechanism proper 187 MIME-Version: 1.0 188 Content-Type: text/plain; charset=US-ASCII 189 190 The handling of the might_cancel queueing is not properly protected, so 191 parallel operations on the file descriptor can race with each other and 192 lead to list corruptions or use after free. 193 194 Protect the context for these operations with a separate lock. 195 196 Reported-by: Foo Bar <foo@bar.com> 197 Signed-off-by: Foo Bar <foo@bar.com> 198 --- 199 fs/timerfd.c | 17 ++++++++++++++--- 200 1 file changed, 14 insertions(+), 3 deletions(-) 201 202 --- a/fs/timerfd.c 203 +++ b/fs/timerfd.c 204 @@ -40,6 +40,7 @@ struct timerfd_ctx { 205 short unsigned settime_flags; /* to show in fdinfo */ 206 struct rcu_head rcu; 207 struct list_head clist; 208 + spinlock_t cancel_lock; 209 bool might_cancel; 210 }; 211 `, 212 title: "timerfd: Protect the might cancel mechanism proper", 213 diff: `--- a/fs/timerfd.c 214 +++ b/fs/timerfd.c 215 @@ -40,6 +40,7 @@ struct timerfd_ctx { 216 short unsigned settime_flags; /* to show in fdinfo */ 217 struct rcu_head rcu; 218 struct list_head clist; 219 + spinlock_t cancel_lock; 220 bool might_cancel; 221 }; 222 `, 223 }, 224 225 { 226 text: `crypto/sha512-mb: Correct initialization value for lane lens 227 diff --git a/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c b/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c 228 index 36870b2..5484d77 100644 229 --- a/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c 230 +++ b/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c 231 @@ -57,10 +57,10 @@ void sha512_mb_mgr_init_avx2(struct sha512_mb_mgr *state) 232 { 233 unsigned int j; 234 235 - state->lens[0] = 0; 236 - state->lens[1] = 1; 237 - state->lens[2] = 2; 238 - state->lens[3] = 3; 239 + state->lens[0] = 0xFFFFFFFF00000000; 240 + state->lens[1] = 0xFFFFFFFF00000001; 241 + state->lens[2] = 0xFFFFFFFF00000002; 242 + state->lens[3] = 0xFFFFFFFF00000003; 243 state->unused_lanes = 0xFF03020100; 244 for (j = 0; j < 4; j++) 245 state->ldata[j].job_in_lane = NULL; 246 -- 247 2.5.5`, 248 title: "crypto/sha512-mb: Correct initialization value for lane lens", 249 diff: `diff --git a/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c ` + 250 `b/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c 251 index 36870b2..5484d77 100644 252 --- a/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c 253 +++ b/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c 254 @@ -57,10 +57,10 @@ void sha512_mb_mgr_init_avx2(struct sha512_mb_mgr *state) 255 { 256 unsigned int j; 257 258 - state->lens[0] = 0; 259 - state->lens[1] = 1; 260 - state->lens[2] = 2; 261 - state->lens[3] = 3; 262 + state->lens[0] = 0xFFFFFFFF00000000; 263 + state->lens[1] = 0xFFFFFFFF00000001; 264 + state->lens[2] = 0xFFFFFFFF00000002; 265 + state->lens[3] = 0xFFFFFFFF00000003; 266 state->unused_lanes = 0xFF03020100; 267 for (j = 0; j < 4; j++) 268 state->ldata[j].job_in_lane = NULL; 269 `, 270 }, 271 272 { 273 text: ` 274 Subject: [Patch net] kcm: fix a null pointer dereference in kcm_sendmsg() 275 276 --- a/fs/timerfd.c 277 +++ b/fs/timerfd.c 278 @@ -40,6 +40,7 @@ struct timerfd_ctx { 279 short unsigned settime_flags; /* to show in fdinfo */ 280 struct rcu_head rcu; 281 struct list_head clist; 282 + spinlock_t cancel_lock; 283 bool might_cancel; 284 }; 285 286 On Fri, Nov 17, 2017 at 3:46 PM, syzbot wrote: 287 `, 288 title: "kcm: fix a null pointer dereference in kcm_sendmsg()", 289 diff: `--- a/fs/timerfd.c 290 +++ b/fs/timerfd.c 291 @@ -40,6 +40,7 @@ struct timerfd_ctx { 292 short unsigned settime_flags; /* to show in fdinfo */ 293 struct rcu_head rcu; 294 struct list_head clist; 295 + spinlock_t cancel_lock; 296 bool might_cancel; 297 }; 298 `, 299 }, 300 301 { 302 text: ` 303 Subject: Re: [PATCH v3] net/irda: fix lockdep annotation 304 305 --- a/fs/timerfd.c 306 +++ b/fs/timerfd.c 307 @@ -40,6 +40,7 @@ struct timerfd_ctx { 308 short unsigned settime_flags; /* to show in fdinfo */ 309 struct rcu_head rcu; 310 struct list_head clist; 311 + spinlock_t cancel_lock; 312 bool might_cancel; 313 }; 314 > Does this help? 315 `, 316 title: "net/irda: fix lockdep annotation", 317 diff: `--- a/fs/timerfd.c 318 +++ b/fs/timerfd.c 319 @@ -40,6 +40,7 @@ struct timerfd_ctx { 320 short unsigned settime_flags; /* to show in fdinfo */ 321 struct rcu_head rcu; 322 struct list_head clist; 323 + spinlock_t cancel_lock; 324 bool might_cancel; 325 }; 326 `, 327 }, 328 329 { 330 text: `syz-dash: first version of dashboard app 331 diff --git a/syz-dash/api.go b/syz-dash/api.go 332 new file mode 100644 333 index 0000000..a1a0499 334 --- /dev/null 335 +++ b/syz-dash/api.go 336 @@ -0,0 +1,444 @@ 337 +package dash 338 `, 339 title: "syz-dash: first version of dashboard app", 340 diff: `diff --git a/syz-dash/api.go b/syz-dash/api.go 341 new file mode 100644 342 index 0000000..a1a0499 343 --- /dev/null 344 +++ b/syz-dash/api.go 345 @@ -0,0 +1,444 @@ 346 +package dash 347 `, 348 }, 349 { 350 text: `Subject: multi-file patch 351 352 diff --git a/init/main.c b/init/main.c 353 index 0ee9c6866ada..ed01296f7b23 100644 354 --- a/init/main.c 355 +++ b/init/main.c 356 @@ -706,6 +706,8 @@ asmlinkage __visible void __init start_kernel(void) 357 efi_free_boot_services(); 358 } 359 360 + BUG(); 361 + 362 /* Do the rest non-__init'ed, we're now alive */ 363 rest_init(); 364 } 365 diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c 366 index 6f319fb81718..76a8d5aeed4b 100644 367 --- a/mm/kasan/kasan.c 368 +++ b/mm/kasan/kasan.c 369 @@ -42,7 +42,7 @@ 370 371 void kasan_enable_current(void) 372 { 373 - current->kasan_depth++; 374 + current->kasan_depth--; 375 } 376 377 void kasan_disable_current(void) 378 379 > Does this help? 380 `, 381 title: "multi-file patch", 382 diff: `diff --git a/init/main.c b/init/main.c 383 index 0ee9c6866ada..ed01296f7b23 100644 384 --- a/init/main.c 385 +++ b/init/main.c 386 @@ -706,6 +706,8 @@ asmlinkage __visible void __init start_kernel(void) 387 efi_free_boot_services(); 388 } 389 390 + BUG(); 391 + 392 /* Do the rest non-__init'ed, we're now alive */ 393 rest_init(); 394 } 395 diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c 396 index 6f319fb81718..76a8d5aeed4b 100644 397 --- a/mm/kasan/kasan.c 398 +++ b/mm/kasan/kasan.c 399 @@ -42,7 +42,7 @@ 400 401 void kasan_enable_current(void) 402 { 403 - current->kasan_depth++; 404 + current->kasan_depth--; 405 } 406 407 void kasan_disable_current(void) 408 `, 409 }, 410 { 411 text: `Subject: Re: WARNING in usb_submit_urb (4) 412 413 #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git v5.1-rc3 414 415 Index: usb-devel/drivers/usb/core/driver.c 416 =================================================================== 417 --- usb-devel.orig/drivers/usb/core/driver.c 418 +++ usb-devel/drivers/usb/core/driver.c 419 @@ -34,6 +34,9 @@ 420 421 #include "usb.h" 422 423 +#undef dev_vdbg 424 +#define dev_vdbg dev_info 425 + 426 427 /* 428 * Adds a new dynamic USBdevice ID to this driver, 429 Index: usb-devel/drivers/usb/core/hub.c 430 =================================================================== 431 --- usb-devel.orig/drivers/usb/core/hub.c 432 +++ usb-devel/drivers/usb/core/hub.c 433 @@ -36,6 +36,10 @@ 434 #include "hub.h" 435 436 +#undef dev_dbg 437 +#define dev_dbg dev_info 438 + 439 + 440 #define USB_VENDOR_GENESYS_LOGIC 0x05e3 441 #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 442 443 @@ -1016,6 +1020,8 @@ static void hub_activate(struct usb_hub 444 bool need_debounce_delay = false; 445 unsigned delay; 446 447 + dev_info(hub->intfdev, "%s type %d\n", __func__, type); 448 + 449 /* Continue a partial initialization */ 450 if (type == HUB_INIT2 || type == HUB_INIT3) { 451 device_lock(&hdev->dev); 452 @@ -1254,6 +1260,7 @@ static void hub_activate(struct usb_hub 453 init3: 454 hub->quiescing = 0; 455 456 + dev_info(hub->intfdev, "Submitting status URB\n"); 457 status = usb_submit_urb(hub->urb, GFP_NOIO); 458 if (status < 0) 459 dev_err(hub->intfdev, "activate --> %d\n", status); 460 `, 461 title: "Re: WARNING in usb_submit_urb (4)", 462 diff: `Index: usb-devel/drivers/usb/core/driver.c 463 =================================================================== 464 --- usb-devel.orig/drivers/usb/core/driver.c 465 +++ usb-devel/drivers/usb/core/driver.c 466 @@ -34,6 +34,9 @@ 467 468 #include "usb.h" 469 470 +#undef dev_vdbg 471 +#define dev_vdbg dev_info 472 + 473 474 /* 475 * Adds a new dynamic USBdevice ID to this driver, 476 Index: usb-devel/drivers/usb/core/hub.c 477 =================================================================== 478 --- usb-devel.orig/drivers/usb/core/hub.c 479 +++ usb-devel/drivers/usb/core/hub.c 480 @@ -36,6 +36,10 @@ 481 #include "hub.h" 482 483 +#undef dev_dbg 484 +#define dev_dbg dev_info 485 + 486 + 487 #define USB_VENDOR_GENESYS_LOGIC 0x05e3 488 #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 489 490 @@ -1016,6 +1020,8 @@ static void hub_activate(struct usb_hub 491 bool need_debounce_delay = false; 492 unsigned delay; 493 494 + dev_info(hub->intfdev, "%s type %d\n", __func__, type); 495 + 496 /* Continue a partial initialization */ 497 if (type == HUB_INIT2 || type == HUB_INIT3) { 498 device_lock(&hdev->dev); 499 @@ -1254,6 +1260,7 @@ static void hub_activate(struct usb_hub 500 init3: 501 hub->quiescing = 0; 502 503 + dev_info(hub->intfdev, "Submitting status URB\n"); 504 status = usb_submit_urb(hub->urb, GFP_NOIO); 505 if (status < 0) 506 dev_err(hub->intfdev, "activate --> %d\n", status); 507 `, 508 }, 509 { 510 text: `Some 511 Text 512 Without 513 Any 514 Diff 515 `, 516 diff: "", 517 title: "test empty patch", 518 }, 519 }