sys/openbsd: prevent swap partition device nodes from being created

Writing to the swap partition during fuzzing can lead to all kinds of
corruptions[1].

[1] https://syzkaller.appspot.com/bug?id=a2eca15e6e0be4be3ed1b0b2bab3332edc317b1c
This commit is contained in:
Anton Lindqvist 2019-07-21 10:49:42 +02:00 committed by Dmitry Vyukov
parent 1656845f45
commit 919efc620a
2 changed files with 15 additions and 4 deletions

View File

@ -112,9 +112,10 @@ func (arch *arch) SanitizeCall(c *prog.Call) {
dev.Val = devNullDevT
}
// Prevent /dev/sd0c nodes from being created since the refer to
// the raw root disk.
if devmajor(dev.Val) == 4 && devminor(dev.Val) == 2 {
// Prevent /dev/sd0b (swap partition) and /dev/sd0c (raw disk)
// nodes from being created. Writing to such devices can corrupt
// the file system.
if devmajor(dev.Val) == 4 && (devminor(dev.Val) == 1 || devminor(dev.Val) == 2) {
dev.Val = devNullDevT
}
case "mlockall":

View File

@ -41,9 +41,19 @@ func TestSanitizeCall(t *testing.T) {
`mknod(0x0, 0x0, 0x1600)`,
`mknod(0x0, 0x0, 0x1600)`,
},
{
// major=4, minor=0
`mknod(0x0, 0x0, 0x400)`,
`mknod(0x0, 0x0, 0x400)`,
},
{
// major=4, minor=1
`mknod(0x0, 0x0, 0x401)`,
`mknod(0x0, 0x0, 0x202)`,
},
{
// major=4, minor=2
`mknod(0x0, 0x0, 0x0402)`,
`mknod(0x0, 0x0, 0x402)`,
`mknod(0x0, 0x0, 0x202)`,
},
{