Bug 2231923 - Smaps file parsing in DNF's needs-restarting cannot handle garbage UTF-8-ish characters in smaps lines
Summary: Smaps file parsing in DNF's needs-restarting cannot handle garbage UTF-8-ish ...
Keywords:
Status: POST
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: dnf-plugins-core
Version: 9.2
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Jan Kolarik
QA Contact: swm-qe
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-08-14 17:05 UTC by Jonathan Wright
Modified: 2023-08-15 06:37 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 2212953 0 unspecified POST Smaps file parsing in DNF's needs-restarting cannot handle garbage UTF-8-ish characters in smaps lines 2023-08-15 05:11:41 UTC
Red Hat Issue Tracker RHELPLAN-165751 0 None None None 2023-08-15 06:37:03 UTC

Internal Links: 2212953

Description Jonathan Wright 2023-08-14 17:05:40 UTC
Description of problem:
Occasionally when needs-restarting is ran, a component which requires restart may have an open fd corresponding to an entry in the smaps table with garbage characters in them. When this occurs, needs-restarting exits nonzero with a stacktrace referencing the attempt to read non-ascii lines from a filehandle established on line 77 of needs-restarting.py. This shouldn't be all that surprising, given the smaps file is in fact just binary content and not an encoded text file, but even then in 99% or more of cases I'd suspect this would still be fine to not handle.

Version-Release number of selected component (if applicable):
4.0.21-19 (dnf-plugins-core-4.0.21-19.el8_8.noarch)

How reproducible:
My best guess was to ensure one of the services which needs restarting was holding open a file with UTF-8 characters in the filename then run needs-restarting. This is... rather difficult to actually hit out in the wild, and at cPanel we've only seen it from customers reporting it to us after getting failure emails about needs-restarting. As such I went for a contrived approach within a unit test to reproduce the issue.

Steps to Reproduce:
See test in forthcoming pull request. I have no idea how people actually hit this in the wild, but we've got enough complaints about it that I can say it is a real problem.

Actual results:
  File "/usr/bin/needs-restarting", line 101, in <module>
    main.user_main(MAPPING[command] + args, exit_code=True)
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 201, in user_main
    errcode = main(args)
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 67, in main
    return _main(base, args, cli_class, option_parser_class)
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 106, in _main
    return cli_run(cli, base)
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 122, in cli_run
    cli.run()
  File "/usr/lib/python3.6/site-packages/dnf/cli/cli.py", line 1055, in run 
    return self.command.run()
  File "/usr/lib/python3.6/site-packages/dnf-plugins/needs_restarting.py", line 270, in run 
    for ofile in list_opened_files(uid):
  File "/usr/lib/python3.6/site-packages/dnf-plugins/needs_restarting.py", line 77, in list_opened_files
    lines = smaps_file.readlines()
  File "/usr/lib64/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1562: ordinal not in range(128)

Expected results:
No nonzero exit, no stacktrace.

Additional info:
https://github.com/rpm-software-management/dnf-plugins-core/pull/494

Comment 1 Jan Kolarik 2023-08-15 05:10:58 UTC
Original RHEL 8 bug: https://bugzilla.redhat.com/show_bug.cgi?id=2212953.


Note You need to log in before you can comment on or make changes to this bug.