File: core-prevent-race-condition-on-proc-PID-exec-evaluat.patch

package info (click to toggle)
needrestart 3.6-4%2Bdeb12u3
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 936 kB
  • sloc: perl: 3,371; sh: 277; makefile: 82
file content (34 lines) | stat: -rw-r--r-- 1,158 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
From 99d954da8122122fa18bce061fcf2fb307135b64 Mon Sep 17 00:00:00 2001
From: Thomas Liske <thomas@fiasko-nw.net>
Date: Sat, 12 Oct 2024 16:05:30 +0200
Subject: [PATCH 1/5] core: prevent race condition on /proc/$PID/exec
 evaluation

---
 needrestart | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/needrestart b/needrestart
index cad58c3..d8cb9a5 100755
--- a/needrestart
+++ b/needrestart
@@ -530,11 +530,16 @@ if(defined($opt_l)) {
 	# orphaned binary
 	$restart++ if (defined($exe) && $exe =~ s/ \(deleted\)$//);  # Linux
 	$restart++ if (defined($exe) && $exe =~ s/^\(deleted\)//);   # Linux VServer
+	$restart++ unless(defined($ptable->{$pid}->{exec}));
 	print STDERR "$LOGPREF #$pid uses obsolete binary $exe\n" if($restart && $nrconf{verbosity} > 1);
 
 	# ignore blacklisted binaries
 	next if(grep { $exe =~ /$_/; } @{$nrconf{blacklist}});
 
+	# Sync $exe with the initial value from Proc:ProcessTable to prevent race
+	# conditions in later checks.
+	$exe = $ptable->{$pid}->{exec} if(defined($ptable->{$pid}->{exec}));
+
 	# read file mappings (Linux 2.0+)
 	unless($restart) {
 	    if(open(HMAP, '<', "/proc/$pid/maps")) {
-- 
2.39.5