Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bug#1026927: needrestart -b on AMD processors complains of perl uninitialized variable

64 views
Skip to first unread message

George Robbert

unread,
Dec 23, 2022, 8:40:03 PM12/23/22
to
Package: needrestart
Version: 3.5-4+deb11u2
Severity: normal

Dear Maintainer,

When running 'needrestart -b' on an AMD system, I get the following
uninitialized variable warning. It also does not report the expected
microcode version (NEEDRESTART-UCEXP). See output: section below for
example output of needrestart -b.

Use of uninitialized value $ucode_vars{"AVAIL"} in concatenation (.) or string at /usr/sbin/needrestart line 904.

This perl warning disappears when adding the -v option (needrestart -b -v),
and the correct value is reported for NEEDRESTART-UCEXP.

The processor, in this system, is:

vendor_id : AuthenticAMD
cpu family : 18
model : 1
model name : AMD A4-3400 APU with Radeon(tm) HD Graphics
stepping : 0
microcode : 0x3000027



It looks to me like the problem is that line 182 of
/usr/share/perl5/NeedRestart/uCode/AMD.pm ends in a comma (,) instead
of a semicolon (;). This means that assignment is subsumed into the
next line which is under if ($debug).

See the attached patch.

It also looks to me like this is similar symptoms with a different
root cause from bug #973050.


Thanks,
George Robbert


-- Package-specific info:
needrestart output:



-- System Information:
Debian Release: 11.1
Architecture: amd64 (x86_64)

Kernel: Linux 5.10.0-20-amd64 (SMP w/2 CPU threads)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=ANSI_X3.4-1968) (ignored: LC_ALL set to C), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: sysvinit (via /sbin/init)

Versions of packages needrestart depends on:
ii binutils 2.35.2-2
ii dpkg 1.20.12
ii gettext-base 0.21-4
ii libintl-perl 1.26-3+deb11u1
ii libmodule-find-perl 0.15-1
ii libmodule-scandeps-perl 1.30-1
ii libproc-processtable-perl 0.59-2+b1
ii libsort-naturally-perl 1.03-2
ii libterm-readkey-perl 2.38-1+b2
ii perl 5.32.1-4+deb11u2
ii xz-utils 5.2.5-2.1~deb11u1

Versions of packages needrestart recommends:
ii libpam-elogind [libpam-systemd] 246.10-2
ii sysvinit-core 2.96-7+devuan2

Versions of packages needrestart suggests:
pn iucode-tool <none>
pn needrestart-session | libnotify-bin <none>

-- Configuration Files:
/etc/apt/apt.conf.d/99needrestart changed:
DPkg::Post-Invoke {"test -x /usr/lib/needrestart/apt-pinvoke && /usr/lib/needrestart/apt-pinvoke -b || true"; };

/etc/needrestart/hook.d/20-rpm [Errno 2] No such file or directory: '/etc/needrestart/hook.d/20-rpm'

-- no debconf information
needrestart.patch

George Robbert

unread,
Jan 9, 2023, 3:10:04 PM1/9/23
to
On Fri, 06 Jan 2023 01:56:33 -0700, Patrick Matthäi wrote:
> Thanks for your investigation. I have tested it on my (sid/unstable) AMD
> notebook and I can reproduce your issue with needrestart from stable.
> But your patch does not produce another result for me. Are you sure,
> that you didnt changed something else?

Color me confused. That file (in fact that one character) is all I
changed. I tried it again and the patch seems to work for me. What I
did was:

apt-get install --reinstall needrestart
needrestart -b
# error message
apply patch
needrestart -b
# no error here

I'm attaching a full `script` of that attempt in case there's
something significant in there that the above summary leaves out.
That also has md5sum of AMD.pm before and after the patch in case that
helps point to "what's different" between our two runs.

If there's any more info I can supply, please let me know. Thanks for
looking into this.

Thanks,
George

George Robbert

unread,
Jan 14, 2023, 1:30:03 PM1/14/23
to
Hey,

I think I found why you still get the error after applying the patch.
The same thing happened to me on another of my systems. The
difference was whether the package amd64-microcode was installed or
not. I think I have a patch (attached) for both. Here's what I found.



It looks like there are actually 2 related bugs here. The first one
(which my original patch for line 182 addresses) applies when there is
microcode available. The second, when there is not. Here's what I've
found:

Both of these are exposed on line 904 of /usr/sbin/needrestart

print "NEEDRESTART-UCEXP: $ucode_vars{AVAIL}\n";

when $ucode_vars{AVAIL} never gets set. There are 2 ways this can
happen. The second (which I just found), comes when AMD.pm finds an
AMD cpu, but does not find microcode for it (namely _scan_ucodes does
not find a matching file in /lib/firmware/amd-ucode/microcode_*.bin).
This will, under -v, print

"$LOGPREF #$info->{processor} no ucode updates available\n"

and return NRM_CURRENT (indicating no reboot for microcode needed),
but still leave $ucode_vars{AVAIL} unset. The fix is to make sure
that it is set even when there are no microcode updates available (on
line 176).


The first (original patch) bug comes when needrestart finds a matching
microcode. There, on line 182 of /usr/share/perl5/NeedRestart/uCode/AMD.pm
the line ends with a comma (,) instead of a semicolon (;), which means
that the assignment to $ucode_vars{AVAIL} is subsumed under the if ($debug)
condoling the printing of microcode version under. Thus,
$ucode_vars{AVAIL} is only set under needrestart -v.


The attached patch fixes both of these cases.

Thanks,
George

Patrick Matthäi

unread,
Jan 18, 2023, 11:10:04 AM1/18/23
to
fixed #1026927 3.6-1
thanks
> --- /tmp/AMD.pm 2023-01-14 09:09:28.324414456 -0700
> +++ /usr/share/perl5/NeedRestart/uCode/AMD.pm 2023-01-14 09:11:39.210705528 -0700
> @@ -173,13 +173,13 @@
> _scan_ucodes();
> }
>
> - my %vars = ( CURRENT => sprintf( "0x%08x", $ucode ), );
> + my %vars = ( CURRENT => sprintf( "0x%08x", $ucode ), AVAIL => "unavailable");
>
> # check for microcode updates
> if ( exists( $_ucodes->{cpuid}->{$cpuid} ) ) {
> my $prid = $_ucodes->{cpuid}->{$cpuid};
> if ( exists( $_ucodes->{prid}->{$prid} ) ) {
> - $vars{AVAIL} = sprintf( "0x%08x", $_ucodes->{prid}->{$prid} ),
> + $vars{AVAIL} = sprintf( "0x%08x", $_ucodes->{prid}->{$prid} );
>
> print STDERR "$LOGPREF #$info->{processor} found ucode $vars{AVAIL}\n" if ($debug);
> if ( $_ucodes->{prid}->{$prid} > $ucode ) {


Thanks for your new investigation, you were faster than me :)

I verified your patch, working also on my system now. I have filled
#1029147 and will upload a fixed package to stable after I have got the
approve from -release

Thanks for it!
0 new messages