Package: powertop
Version: 1.11-1
Severity: important
Tags: patch

On newer kernels with large config files, powertop fails with a segmentation
fault. For example, this occurs when kernel 2.6.37 is installed for x86-64
using the debian kernel 2.6.32 config file as a starting point. This issue is
sortof fixed in the upstream version 1.13 of powertop 1.13 by increasing the
maximum size of the config file that can be handled and checking the buffer
lengths. Presumably it is too close to release to upgrade a major version so a
patch is attached that will act as a stopgap.



-- System Information:
Debian Release: 6.0
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.37 (SMP w/8 CPU cores)
Locale: LANG=en_IE.utf8, LC_CTYPE=en_IE.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages powertop depends on:
ii  libc6                     2.11.2-7       Embedded GNU C Library: Shared lib
ii  libncursesw5              5.7+20100313-5 shared libraries for terminal hand

powertop recommends no packages.

Versions of packages powertop suggests:
ii  cpufrequtils                  007-1      utilities to deal with the cpufreq
pn  laptop-mode-tools             <none>     (no description available)

-- no debconf information
>From 29ea8074594645f3d01013b9ce0c3e1cea972480 Mon Sep 17 00:00:00 2001
From: Mel Gorman <m...@mekina.109elm.lan>
Date: Sat, 15 Jan 2011 11:53:23 +0000
Subject: [PATCH] Avoid segfaults due to buffer overruns while reading the 
kernel config file

On newer kernels, powertop segfaults when reading the config file. The
problem is that the config is longer than expected and it overruns the
buffer (distressing as this runs as root). Upstream in 1.13, this is
fixed by increasing the maximum size of the config file to 10000 and
checks the buffer is not being overrun. This is what this patch does
as a stopgap measure until the package is synchronised with the
upstream version.

Signed-off-by: Mel Gorman <m...@csn.ul.ie>
---

diff --git a/powertop-1.11/debian/patches/00list 
b/powertop-1.11/debian/patches/00list
index dd28abb..e98f73f 100644
--- a/powertop-1.11/debian/patches/00list
+++ b/powertop-1.11/debian/patches/00list
@@ -1 +1,2 @@
 remove-bashism.dpatch
+increase-configlimit.dpatch
diff --git a/powertop-1.11/debian/patches/increase-configlimit.dpatch 
b/powertop-1.11/debian/patches/increase-configlimit.dpatch
new file mode 100755
index 0000000..57fb41d
--- /dev/null
+++ b/powertop-1.11/debian/patches/increase-configlimit.dpatch
@@ -0,0 +1,38 @@
+#! /bin/sh /usr/share/dpatch/dpatch-run
+## increase-configlimit.patch.dpatch by  <m...@csn.ul.ie>
+##
+## All lines beginning with `## DP:' are a description of the patch.
+## DP: No description.
+
+@DPATCH@
+diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' 
'--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' 
powertop-1.11~/config.c powertop-1.11/config.c
+--- powertop-1.11~/config.c    2011-01-15 11:51:23.000000000 +0000
++++ powertop-1.11/config.c     2011-01-15 11:58:55.494107143 +0000
+@@ -33,7 +33,8 @@
+ #include "powertop.h"
+ 
+ /* static arrays are not nice programming.. but they're easy */
+-static char configlines[5000][100];
++#define MAXCONFIGLINES 10000
++static char configlines[MAXCONFIGLINES][100];
+ static int configcount;
+ 
+ static void read_kernel_config(void)
+@@ -49,6 +50,8 @@
+                       char line[100];
+                       if (fgets(line, 100, file) == NULL)
+                               break;
++                      if (configcount >= MAXCONFIGLINES)
++                              break;
+                       strcpy(configlines[configcount++], line);
+               }
+               pclose(file);
+@@ -77,6 +80,8 @@
+               char line[100];
+               if (fgets(line, 100, file) == NULL)
+                       break;
++              if (configcount >= MAXCONFIGLINES)
++                      break;
+               strcpy(configlines[configcount++], line);
+       }
+       fclose(file);

Reply via email to