Commit 7e71b1e
Julien Grall
tools/xenstored: Prevent a buffer overflow in dump_state_node_perms()
ASAN reported one issue when Live Updating Xenstored:
=================================================================
==873==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffc194f53e0 at pc 0x555c6b323292 bp 0x7ffc194f5340 sp 0x7ffc194f5338
WRITE of size 1 at 0x7ffc194f53e0 thread T0
#0 0x555c6b323291 in dump_state_node_perms xen/tools/xenstore/xenstored_core.c:2468
#1 0x555c6b32746e in dump_state_special_node xen/tools/xenstore/xenstored_domain.c:1257
#2 0x555c6b32a702 in dump_state_special_nodes xen/tools/xenstore/xenstored_domain.c:1273
xen-project#3 0x555c6b32ddb3 in lu_dump_state xen/tools/xenstore/xenstored_control.c:521
xen-project#4 0x555c6b32e380 in do_lu_start xen/tools/xenstore/xenstored_control.c:660
xen-project#5 0x555c6b31b461 in call_delayed xen/tools/xenstore/xenstored_core.c:278
xen-project#6 0x555c6b32275e in main xen/tools/xenstore/xenstored_core.c:2357
xen-project#7 0x7f95eecf3d09 in __libc_start_main ../csu/libc-start.c:308
xen-project#8 0x555c6b3197e9 in _start (/usr/local/sbin/xenstored+0xc7e9)
Address 0x7ffc194f53e0 is located in stack of thread T0 at offset 80 in frame
#0 0x555c6b32713e in dump_state_special_node xen/tools/xenstore/xenstored_domain.c:1232
This frame has 2 object(s):
[32, 40) 'head' (line 1233)
[64, 80) 'sn' (line 1234) <== Memory access at offset 80 overflows this variable
This is happening because the callers are passing a pointer to a variable
allocated on the stack. However, the field perms is a dynamic array, so
Xenstored will end up to read outside of the variable.
Rework the code so the permissions are written one by one in the fd.
Fixes: ed6eebf ("tools/xenstore: dump the xenstore state for live update")
Signed-off-by: Julien Grall <[email protected]>
Reviewed-by: Juergen Gross <[email protected]>
Reviewed-by: Luca Fancellu <[email protected]>1 parent 3f56835 commit 7e71b1e
File tree
3 files changed
+16
-15
lines changed- tools/xenstore
3 files changed
+16
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2447 | 2447 | | |
2448 | 2448 | | |
2449 | 2449 | | |
2450 | | - | |
2451 | | - | |
| 2450 | + | |
2452 | 2451 | | |
2453 | 2452 | | |
2454 | 2453 | | |
2455 | 2454 | | |
2456 | 2455 | | |
| 2456 | + | |
| 2457 | + | |
2457 | 2458 | | |
2458 | 2459 | | |
2459 | | - | |
| 2460 | + | |
2460 | 2461 | | |
2461 | 2462 | | |
2462 | | - | |
| 2463 | + | |
2463 | 2464 | | |
2464 | 2465 | | |
2465 | | - | |
| 2466 | + | |
2466 | 2467 | | |
2467 | 2468 | | |
2468 | | - | |
| 2469 | + | |
2469 | 2470 | | |
2470 | 2471 | | |
2471 | | - | |
| 2472 | + | |
2472 | 2473 | | |
2473 | | - | |
2474 | | - | |
| 2474 | + | |
2475 | 2475 | | |
2476 | | - | |
2477 | | - | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
2478 | 2480 | | |
2479 | 2481 | | |
2480 | 2482 | | |
| |||
2519 | 2521 | | |
2520 | 2522 | | |
2521 | 2523 | | |
2522 | | - | |
| 2524 | + | |
2523 | 2525 | | |
2524 | 2526 | | |
2525 | 2527 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
274 | | - | |
275 | | - | |
| 274 | + | |
276 | 275 | | |
277 | 276 | | |
278 | 277 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1254 | 1254 | | |
1255 | 1255 | | |
1256 | 1256 | | |
1257 | | - | |
| 1257 | + | |
1258 | 1258 | | |
1259 | 1259 | | |
1260 | 1260 | | |
| |||
0 commit comments