Skip to content

Commit b78611d

Browse files
committed
Add ifrname_override option to work around some sockets ioctl errors
1 parent 65606d2 commit b78611d

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

qiling/os/posix/posix.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,15 @@ def __init__(self, ql: Qiling):
9999
self.ql = ql
100100
self.sigaction_act = [0] * 256
101101

102-
self.uid = self.euid = self.profile.getint("KERNEL","uid")
103-
self.gid = self.egid = self.profile.getint("KERNEL","gid")
104-
105-
self.pid = self.profile.getint("KERNEL", "pid")
106-
self.ipv6 = self.profile.getboolean("NETWORK", "ipv6")
107-
self.bindtolocalhost = self.profile.getboolean("NETWORK", "bindtolocalhost")
102+
conf = self.profile['KERNEL']
103+
self.uid = self.euid = conf.getint('uid')
104+
self.gid = self.egid = conf.getint('gid')
105+
self.pid = conf.getint('pid')
106+
107+
conf = self.profile['NETWORK']
108+
self.ipv6 = conf.getboolean('ipv6')
109+
self.bindtolocalhost = conf.getboolean('bindtolocalhost')
110+
self.ifrname_ovr = conf.get('ifrname_override')
108111

109112
self.posix_syscall_hooks = {
110113
QL_INTERCEPT.CALL : {},

qiling/os/posix/syscall/ioctl.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ def ioctl(_fd: int, _cmd: int, _arg: int):
8181
if isinstance(ql.os.fd[fd], ql_socket) and cmd in (SIOCGIFADDR, SIOCGIFNETMASK):
8282
data = ql.mem.read(arg, 64)
8383

84+
ifr_name_override = ql.os.ifrname_ovr
85+
86+
if ifr_name_override is not None:
87+
# make sure the interface name does not exceed 16 characters.
88+
# pad it with null bytes if shorter
89+
ifr_name_override = ifr_name_override[:16].ljust(16, '\x00')
90+
91+
data[0:16] = ifr_name_override.encode()
92+
8493
try:
8594
data = ql.os.fd[fd].ioctl(cmd, bytes(data))
8695
except OSError as ex:

qiling/profiles/linux.ql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ current_path = /
3232

3333

3434
[NETWORK]
35+
# override the ifr_name field in ifreq structures to match the hosts network interface name.
36+
# that fixes certain socket ioctl errors where the requested interface name does not match the
37+
# one on the host. comment out to avoid override
38+
ifrname_override = eth0
39+
3540
# To use IPv6 or not, to avoid binary double bind. ipv6 and ipv4 bind the same port at the same time
3641
bindtolocalhost = True
3742
# Bind to localhost

0 commit comments

Comments
 (0)