Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
This file details the changelog of Qiling Framework.

------------------------------------
[Unreleased]

- Validate fstatfs descriptors using the guest ABI width.

------------------------------------
[Version 1.4.6]: August 4th, 2023

Expand Down
6 changes: 6 additions & 0 deletions qiling/os/posix/syscall/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,12 @@ def ql_syscall_rmdir(ql: Qiling, pathname: int):


def ql_syscall_fstatfs(ql: Qiling, fd: int, buf: int):
# The guest syscall ABI passes fstatfs descriptors as 32-bit integers.
fd &= 0xFFFFFFFF

if fd not in range(NR_OPEN) or ql.os.fd[fd] is None:
return -EBADF

data = b"0" * (12 * 8) # for now, just return 0s
regreturn = 0

Expand Down
29 changes: 29 additions & 0 deletions tests/test_fstatfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import unittest
from unittest.mock import Mock

from qiling.os.posix.const import EBADF, NR_OPEN
from qiling.os.posix.syscall.stat import ql_syscall_fstatfs


class FstatfsTest(unittest.TestCase):
def setUp(self):
self.ql = Mock()
self.ql.os.fd = [None] * NR_OPEN
self.ql.os.fd[0] = object()

def test_invalid_fd_returns_ebadf_without_copyout(self):
for fd in (-1, 3, NR_OPEN, 0xFFFFFFFFFFFFFFFF):
with self.subTest(fd=fd):
self.assertEqual(
-EBADF,
ql_syscall_fstatfs(self.ql, fd, 0x1000),
)
self.ql.mem.write.assert_not_called()

def test_valid_fd_preserves_existing_copyout(self):
self.assertEqual(0, ql_syscall_fstatfs(self.ql, 0, 0x1000))
self.ql.mem.write.assert_called_once_with(0x1000, b"0" * (12 * 8))

def test_riscv64_ignores_bits_above_the_32_bit_fd(self):
self.assertEqual(0, ql_syscall_fstatfs(self.ql, 0x100000000, 0x1000))
self.ql.mem.write.assert_called_once_with(0x1000, b"0" * (12 * 8))
1 change: 1 addition & 0 deletions tests/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import unittest

from test_elf import *
from test_fstatfs import *
from test_riscv import *
from test_qltool import *

Expand Down