p2p: Fix Device Address updates from Probe Requests
Andrew Zaborowski
PATCH 1/4 p2p: Fix Device Address updates from Probe Requests
p2p_peer_update_existing may be called with a scan_bss struct built from a Probe Request frame so it can't access bss->p2p_probe_resp_info even if peer->bss was built from a Probe Response. Check the source frame type of the scan_bss struct before updating the Device Address.
This fixes one timing issue that would make the autotest fail often.
--- src/p2p.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
src/p2p.c +7 -3
@@ -3655,11 +3655,15 @@ static bool p2p_peer_update_existing(struct scan_bss *bss,* Some property changes may need to be notified here. */ -if (peer->device_addr == peer->bss->addr) - peer->device_addr = bss->addr; -else +if (bss->source_frame ==SCAN_BSS_PROBE_RESP ) peer->device_addr = bss->p2p_probe_resp_info->device_info.device_addr; +else if (bss->source_frame ==SCAN_BSS_PROBE_REQ && !l_memeqzero ( + bss->p2p_probe_req_info->device_info.device_addr,6 )) + peer->device_addr = + bss->p2p_probe_req_info->device_info.device_addr; +else + peer->device_addr = bss->addr;scan_bss_free (peer->bss); peer->bss = bss;
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 2/4 test-runner: Fix checks in exit_vm
We check that config is not None but then access config.ctx outside of that if block anyway. Then we do the same for config.ctx and config.ctx.args. Nest the if blocks for the checks to be useful.
--- tools/test-runner | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
tools/test-runner +8 -8
@@ -61,15 +61,15 @@ def exit_vm(): print("Process %s still running!" % p.args[0]) p.kill() - if config.ctx and config.ctx.results: - success = print_results(config.ctx.results) - else: - success = False + if config.ctx and config.ctx.results: + success = print_results(config.ctx.results) + else: + success = False - if config.ctx.args.result: - result = 'PASS' if success else 'FAIL' - with open(config.ctx.args.result, 'w') as f: - f.write(result) + if config.ctx and config.ctx.args.result: + result = 'PASS' if success else 'FAIL' + with open(config.ctx.args.result, 'w') as f: + f.write(result) os.sync()
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 3/4 test-runner: Don't require SUDO_GID to be set for logs
In reply to Andrew ZaborowskiBase the root user check on os.getuid() instead of SUDO_GID so as not to implicitly require sudo. SUDO_GID being set doesn't guarantee that the effective user is root either since you can sudo to non-root accounts.
--- tools/test-runner | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-)
tools/test-runner +26 -21
@@ -276,13 +276,16 @@ class Process(subprocess.Popen): return True def _append_outfile(self, file, append=True): - gid = int(self.ctx.args.log_gid) - uid = int(self.ctx.args.log_uid) dir = os.path.dirname(file) + if self.ctx.args.log_gid: + gid = int(self.ctx.args.log_gid) + uid = int(self.ctx.args.log_uid) + if not path_exists(dir): os.mkdir(dir) - os.chown(dir, uid, gid) + if self.ctx.args.log_gid: + os.chown(dir, uid, gid) file = os.path.join(dir,file)
@@ -299,7 +302,8 @@ class Process(subprocess.Popen): traceback.print_exc() exit(0) - os.fchown(f.fileno(), uid, gid) + if self.ctx.args.log_gid: + os.fchown(f.fileno(), uid, gid) self.write_fds.append(f)
@@ -1833,46 +1837,47 @@ class Main: if self.args.sub_tests: options += ' --sub_tests %s' % ','.join(self.args.sub_tests) + gid = None + if os.environ.get('SUDO_GID', None): + uid = int(os.environ['SUDO_UID']) + gid = int(os.environ['SUDO_GID']) + + append_gid_uid = False + if self.args.log: - if os.environ.get('SUDO_GID', None) is None: + if os.getuid() != 0: print("--log can only be used as root user") quit() self.args.log = os.path.abspath(self.args.log) - uid = int(os.environ['SUDO_UID']) - gid = int(os.environ['SUDO_GID']) + append_gid_uid = True if not path_exists(self.args.log): os.mkdir(self.args.log) - os.chown(self.args.log, uid, gid) - - options += ' --log-gid %u' % gid - options += ' --log-uid %u' % uid + if gid: + os.chown(self.args.log, uid, gid) if self.args.monitor: - if os.environ.get('SUDO_GID', None) is None: + if os.getuid() != 0: print("--monitor can only be used as root user") quit() self.args.monitor = os.path.abspath(self.args.monitor) mon_parent_dir = os.path.abspath(os.path.join(self.args.monitor, os.pardir)) - - options += ' --log-gid %u' % int(os.environ['SUDO_GID']) - options += ' --log-uid %u' % int(os.environ['SUDO_UID']) + append_gid_uid = True if self.args.result: - if os.environ.get('SUDO_GID', None) is None: + if os.getuid() != 0: print("--result can only be used as root user") quit() self.args.result = os.path.abspath(self.args.result) result_parent_dir = os.path.abspath(os.path.join(self.args.result, os.pardir)) + append_gid_uid = True - if '--log-gid' not in options: - options += ' --log-gid %u' % int(os.environ['SUDO_GID']) - - if '--log-uid' not in options: - options += ' --log-uid %u' % int(os.environ['SUDO_UID']) + if append_gid_uid and gid: + options += ' --log-gid %u' % (gid,) + options += ' --log-uid %u' % (uid,) denylist = [ 'auto_tests',
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 4/4 test-runner: Replace exit with sys.exit
In reply to Andrew Zaborowskiexit comes from the site module which is "useful for the interactive interpreter shell and should not be used in programs."
(https://docs.python.org/3/library/constants.html#constants-added-by-the-site-module)
Replace with sys.exit(). I for an undefined error for exit in exit_vm().
--- tools/test-runner | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/test-runner +4 -4
@@ -300,7 +300,7 @@ class Process(subprocess.Popen): f = open(os.path.join(dir, file), mode) except Exception as e: traceback.print_exc() - exit(0) + sys.exit(0) if self.ctx.args.log_gid: os.fchown(f.fileno(), uid, gid)
@@ -1545,11 +1545,11 @@ def run_auto_tests(ctx, args): os.chdir(tests[0]) os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = ctx.dbus_address os.system('/bin/bash') - exit() + sys.exit() if len(subtests) < 1: dbg("No tests to run") - exit() + sys.exit() rqueue = multiprocessing.Queue() p = multiprocessing.Process(target=start_test, args=(ctx, subtests, rqueue))
@@ -1994,7 +1994,7 @@ if __name__ == '__main__': prepare_sandbox() run_tests() - exit() + sys.exit() main = Main() main.start()
Signature · 1 line
2.32.0
James Prestwood
Hi Andrew,
Quoted 8 lines · Andrew Zaborowski
p2p_peer_update_existingmay be called with ascan_bssstruct built from
a Probe Request frame so it can't accessbss->p2p_probe_resp_infoeven
ifpeer->bsswas built from a Probe Response. Check the source frame type of thescan_bssstruct before updating the Device Address.This fixes one timing issue that would make the autotest fail often.
So I'm still seeing test_3_go_go_neg_responder and test_4_go_go_neg_initiator failing, but the other two pass now.
Quoted 32 lines
---
src/p2p.c | 10 +++++++---1 file changed, 7 insertions(+), 3 deletions(-)src/p2p.c +0
-0@@ -3655,11 +3655,15 @@ static bool p2p_peer_update_existing(structscan_bss *bss, * Some property changes may need to be notified here. */
- if (peer->device_addr==peer->bss->addr) - peer->device_addr =bss->addr; - else
+ if (bss->source_frame==SCAN_BSS_PROBE_RESP)peer->device_addr= bss->p2p_probe_resp_info-Quoted 1 line
device_info.device_addr;
+ else if (
bss->source_frame==SCAN_BSS_PROBE_REQ&& !l_memeqzero(
+ bss->p2p_probe_req_info-Quoted 1 line
device_info.device_addr, 6))
+ peer->device_addr =
+ bss->p2p_probe_req_info-Quoted 1 line
device_info.device_addr;
+ else
+ peer->device_addr =bss->addr;
scan_bss_free(peer->bss);
peer->bss = bss;
Denis Kenzior
Hi Andrew,
Quoted 10 lines · Andrew Zaborowski
p2p_peer_update_existingmay be called with ascan_bssstruct built from a Probe Request frame so it can't accessbss->p2p_probe_resp_infoeven ifpeer->bsswas built from a Probe Response. Check the source frame type of thescan_bssstruct before updating the Device Address.This fixes one timing issue that would make the autotest fail often.
--- src/p2p.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
All applied, thanks.
Regards,
-Denis