Fixed buffer overflow in cpufreq tunables on systems with many CPUs
(by tunable-overflow-fix patch)
This commit is contained in:
parent
57d89b4932
commit
879378332a
271
powertop-2.5-tunable-overflow-fix.patch
Normal file
271
powertop-2.5-tunable-overflow-fix.patch
Normal file
@ -0,0 +1,271 @@
|
||||
diff --git a/src/tuning/bluetooth.cpp b/src/tuning/bluetooth.cpp
|
||||
index e0bdf12..01c673d 100644
|
||||
--- a/src/tuning/bluetooth.cpp
|
||||
+++ b/src/tuning/bluetooth.cpp
|
||||
@@ -46,8 +46,8 @@
|
||||
bt_tunable::bt_tunable(void) : tunable("", 1.0, "Good", "Bad", "Unknown")
|
||||
{
|
||||
sprintf(desc, _("Bluetooth device interface status"));
|
||||
- strcpy(toggle_bad, "/usr/sbin/hciconfig hci0 up &> /dev/null &");
|
||||
- strcpy(toggle_good, "/usr/sbin/hciconfig hci0 down &> /dev/null");
|
||||
+ toggle_bad = "/usr/sbin/hciconfig hci0 up &> /dev/null &";
|
||||
+ toggle_good = "/usr/sbin/hciconfig hci0 down &> /dev/null";
|
||||
}
|
||||
|
||||
|
||||
@@ -188,9 +188,9 @@ const char *bt_tunable::toggle_script(void)
|
||||
good = good_bad();
|
||||
|
||||
if (good == TUNE_GOOD) {
|
||||
- return toggle_bad;
|
||||
+ return toggle_bad.c_str();
|
||||
}
|
||||
- return toggle_good;
|
||||
+ return toggle_good.c_str();
|
||||
}
|
||||
|
||||
|
||||
diff --git a/src/tuning/cpufreq.cpp b/src/tuning/cpufreq.cpp
|
||||
index c169e6e..f696c89 100644
|
||||
--- a/src/tuning/cpufreq.cpp
|
||||
+++ b/src/tuning/cpufreq.cpp
|
||||
@@ -189,7 +189,7 @@ const char *cpufreq_tunable::toggle_script(void) {
|
||||
int good;
|
||||
good = good_bad();
|
||||
|
||||
- strcpy(toggle_good, "/sbin/modprobe cpufreq_ondemand > /dev/null 2>&1\n");
|
||||
+ toggle_good = "/sbin/modprobe cpufreq_ondemand > /dev/null 2>&1\n";
|
||||
|
||||
if (good == TUNE_GOOD) {
|
||||
dir = opendir("/sys/devices/system/cpu");
|
||||
@@ -202,12 +202,12 @@ const char *cpufreq_tunable::toggle_script(void) {
|
||||
sprintf(filename, "/sys/devices/system/cpu/%s/cpufreq/scaling_governor", dirent->d_name);
|
||||
if (stat(filename, &statbuf) == -1)
|
||||
continue;
|
||||
- sprintf(tmp, "echo '%s' > '%s';\n", original, filename);
|
||||
- strcat(toggle_good, tmp);
|
||||
+ snprintf(tmp, 4096, "echo '%s' > '%s';\n", original, filename);
|
||||
+ toggle_good += tmp;
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
- return toggle_good;
|
||||
+ return toggle_good.c_str();
|
||||
}
|
||||
|
||||
dir = opendir("/sys/devices/system/cpu");
|
||||
@@ -220,12 +220,12 @@ const char *cpufreq_tunable::toggle_script(void) {
|
||||
sprintf(filename, "/sys/devices/system/cpu/%s/cpufreq/scaling_governor", dirent->d_name);
|
||||
if (stat(filename, &statbuf) == -1)
|
||||
continue;
|
||||
- sprintf(tmp, "echo 'ondemand' > '%s';\n", filename);
|
||||
- strcat(toggle_good, tmp);
|
||||
+ snprintf(tmp, 4096, "echo 'ondemand' > '%s';\n", filename);
|
||||
+ toggle_good += tmp;
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
- return toggle_good;
|
||||
+ return toggle_good.c_str();
|
||||
}
|
||||
|
||||
|
||||
diff --git a/src/tuning/ethernet.cpp b/src/tuning/ethernet.cpp
|
||||
index 3d36112..f3f0224 100644
|
||||
--- a/src/tuning/ethernet.cpp
|
||||
+++ b/src/tuning/ethernet.cpp
|
||||
@@ -49,11 +49,13 @@ extern void create_all_nics(callback fn);
|
||||
|
||||
ethernet_tunable::ethernet_tunable(const char *iface) : tunable("", 0.3, _("Good"), _("Bad"), _("Unknown"))
|
||||
{
|
||||
+ char tmp[4096];
|
||||
+
|
||||
memset(interf, 0, sizeof(interf));
|
||||
strncpy(interf, iface, sizeof(interf));
|
||||
sprintf(desc, _("Wake-on-lan status for device %s"), iface);
|
||||
- sprintf(toggle_good, "ethtool -s %s wol d;", iface);
|
||||
-
|
||||
+ snprintf(tmp, 4096, "ethtool -s %s wol d;", iface);
|
||||
+ toggle_good = tmp;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +136,7 @@ const char *ethernet_tunable::toggle_script(void)
|
||||
good = good_bad();
|
||||
|
||||
if (good != TUNE_GOOD) {
|
||||
- return toggle_good;
|
||||
+ return toggle_good.c_str();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
diff --git a/src/tuning/runtime.cpp b/src/tuning/runtime.cpp
|
||||
index b57d53e..3369976 100644
|
||||
--- a/src/tuning/runtime.cpp
|
||||
+++ b/src/tuning/runtime.cpp
|
||||
@@ -42,6 +42,7 @@ runtime_tunable::runtime_tunable(const char *path, const char *bus, const char *
|
||||
{
|
||||
ifstream file;
|
||||
sprintf(runtime_path, "%s/power/control", path);
|
||||
+ char tmp[4096];
|
||||
|
||||
|
||||
sprintf(desc, _("Runtime PM for %s device %s"), bus, dev);
|
||||
@@ -77,8 +78,10 @@ runtime_tunable::runtime_tunable(const char *path, const char *bus, const char *
|
||||
|
||||
|
||||
}
|
||||
- sprintf(toggle_good, "echo 'auto' > '%s';", runtime_path);
|
||||
- sprintf(toggle_bad, "echo 'on' > '%s';", runtime_path);
|
||||
+ snprintf(tmp, 4096, "echo 'auto' > '%s';", runtime_path);
|
||||
+ toggle_good = tmp;
|
||||
+ snprintf(tmp, 4096, "echo 'on' > '%s';", runtime_path);
|
||||
+ toggle_bad = tmp;
|
||||
}
|
||||
|
||||
int runtime_tunable::good_bad(void)
|
||||
@@ -112,10 +115,10 @@ const char *runtime_tunable::toggle_script(void)
|
||||
good = good_bad();
|
||||
|
||||
if (good == TUNE_GOOD) {
|
||||
- return toggle_bad;
|
||||
+ return toggle_bad.c_str();
|
||||
}
|
||||
|
||||
- return toggle_good;
|
||||
+ return toggle_good.c_str();
|
||||
}
|
||||
|
||||
|
||||
diff --git a/src/tuning/tunable.h b/src/tuning/tunable.h
|
||||
index 3372378..8f90ee2 100644
|
||||
--- a/src/tuning/tunable.h
|
||||
+++ b/src/tuning/tunable.h
|
||||
@@ -26,6 +26,7 @@
|
||||
#define _INCLUDE_GUARD_TUNABLE_H
|
||||
|
||||
#include <vector>
|
||||
+#include <string>
|
||||
|
||||
#include "../lib.h"
|
||||
|
||||
@@ -43,8 +44,8 @@ class tunable {
|
||||
char bad_string[128];
|
||||
char neutral_string[128];
|
||||
protected:
|
||||
- char toggle_good[4096];
|
||||
- char toggle_bad[4096];
|
||||
+ string toggle_good;
|
||||
+ string toggle_bad;
|
||||
public:
|
||||
char desc[4096];
|
||||
double score;
|
||||
diff --git a/src/tuning/tuningsysfs.cpp b/src/tuning/tuningsysfs.cpp
|
||||
index ec1ca6b..aa4ebd5 100644
|
||||
--- a/src/tuning/tuningsysfs.cpp
|
||||
+++ b/src/tuning/tuningsysfs.cpp
|
||||
@@ -43,11 +43,15 @@
|
||||
|
||||
sysfs_tunable::sysfs_tunable(const char *str, const char *_sysfs_path, const char *_target_content) : tunable(str, 1.0, _("Good"), _("Bad"), _("Unknown"))
|
||||
{
|
||||
+ char tmp[4096];
|
||||
+
|
||||
strcpy(sysfs_path, _sysfs_path);
|
||||
strcpy(target_value, _target_content);
|
||||
bad_value[0] = 0;
|
||||
- sprintf(toggle_good, "echo '%s' > '%s';", target_value, sysfs_path);
|
||||
- sprintf(toggle_bad, "echo '%s' > '%s';", bad_value, sysfs_path);
|
||||
+ snprintf(tmp, 4096, "echo '%s' > '%s';", target_value, sysfs_path);
|
||||
+ toggle_good = tmp;
|
||||
+ snprintf(tmp, 4096, "echo '%s' > '%s';", bad_value, sysfs_path);
|
||||
+ toggle_bad = tmp;
|
||||
}
|
||||
|
||||
int sysfs_tunable::good_bad(void)
|
||||
@@ -92,11 +96,11 @@ const char *sysfs_tunable::toggle_script(void) {
|
||||
|
||||
if (good == TUNE_GOOD) {
|
||||
if (strlen(bad_value) > 0)
|
||||
- return toggle_bad;
|
||||
+ return toggle_bad.c_str();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- return toggle_good;
|
||||
+ return toggle_good.c_str();
|
||||
}
|
||||
|
||||
|
||||
diff --git a/src/tuning/tuningusb.cpp b/src/tuning/tuningusb.cpp
|
||||
index 27a6dca..2750121 100644
|
||||
--- a/src/tuning/tuningusb.cpp
|
||||
+++ b/src/tuning/tuningusb.cpp
|
||||
@@ -40,6 +40,7 @@ usb_tunable::usb_tunable(const char *path, const char *name) : tunable("", 0.9,
|
||||
char filename[4096];
|
||||
char vendor[2048];
|
||||
char product[2048];
|
||||
+ char tmp[4096];
|
||||
string str1, str2;
|
||||
sprintf(usb_path, "%s/power/control", path);
|
||||
|
||||
@@ -72,8 +73,10 @@ usb_tunable::usb_tunable(const char *path, const char *name) : tunable("", 0.9,
|
||||
else if (strlen(vendor))
|
||||
sprintf(desc, _("Autosuspend for USB device %s [%s]"), vendor, name);
|
||||
|
||||
- sprintf(toggle_good, "echo 'auto' > '%s';", usb_path);
|
||||
- sprintf(toggle_bad, "echo 'on' > '%s';", usb_path);
|
||||
+ snprintf(tmp, 4096, "echo 'auto' > '%s';", usb_path);
|
||||
+ toggle_good = tmp;
|
||||
+ snprintf(tmp, 4096, "echo 'on' > '%s';", usb_path);
|
||||
+ toggle_bad = tmp;
|
||||
}
|
||||
|
||||
int usb_tunable::good_bad(void)
|
||||
@@ -107,10 +110,10 @@ const char *usb_tunable::toggle_script(void)
|
||||
good = good_bad();
|
||||
|
||||
if (good == TUNE_GOOD) {
|
||||
- return toggle_bad;
|
||||
+ return toggle_bad.c_str();
|
||||
}
|
||||
|
||||
- return toggle_good;
|
||||
+ return toggle_good.c_str();
|
||||
}
|
||||
|
||||
static void add_usb_callback(const char *d_name)
|
||||
diff --git a/src/tuning/wifi.cpp b/src/tuning/wifi.cpp
|
||||
index 77cdfcc..2cc01b8 100644
|
||||
--- a/src/tuning/wifi.cpp
|
||||
+++ b/src/tuning/wifi.cpp
|
||||
@@ -44,11 +44,15 @@ extern "C" {
|
||||
|
||||
wifi_tunable::wifi_tunable(const char *_iface) : tunable("", 1.5, _("Good"), _("Bad"), _("Unknown"))
|
||||
{
|
||||
+ char tmp[4096];
|
||||
+
|
||||
strcpy(iface, _iface);
|
||||
sprintf(desc, _("Wireless Power Saving for interface %s"), iface);
|
||||
|
||||
- sprintf(toggle_good, "iw dev %s set power_save on", iface);
|
||||
- sprintf(toggle_bad, "iw dev %s set power_save off", iface);
|
||||
+ snprintf(tmp, 4096, "iw dev %s set power_save on", iface);
|
||||
+ toggle_good = tmp;
|
||||
+ snprintf(tmp, 4096, "iw dev %s set power_save off", iface);
|
||||
+ toggle_bad = tmp;
|
||||
}
|
||||
|
||||
int wifi_tunable::good_bad(void)
|
||||
@@ -78,10 +82,10 @@ const char *wifi_tunable::toggle_script(void)
|
||||
good = good_bad();
|
||||
|
||||
if (good == TUNE_GOOD) {
|
||||
- return toggle_bad;
|
||||
+ return toggle_bad.c_str();
|
||||
}
|
||||
|
||||
- return toggle_good;
|
||||
+ return toggle_good.c_str();
|
||||
}
|
||||
|
||||
void add_wifi_tunables(void)
|
||||
@ -1,6 +1,6 @@
|
||||
Name: powertop
|
||||
Version: 2.5
|
||||
Release: 1%{?dist}
|
||||
Release: 2%{?dist}
|
||||
Summary: Power consumption monitor
|
||||
|
||||
Group: Applications/System
|
||||
@ -14,6 +14,7 @@ Patch0: powertop-2.3-always-create-params.patch
|
||||
Patch1: powertop-2.3-man-fix.patch
|
||||
# Sent upstream (http://github.com/fenrus75/powertop/pull/12)
|
||||
Patch2: powertop-2.3-ondemand-check.patch
|
||||
Patch3: powertop-2.5-tunable-overflow-fix.patch
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||
BuildRequires: gettext, ncurses-devel, pciutils-devel, zlib-devel, libnl3-devel
|
||||
Requires(post): coreutils
|
||||
@ -27,6 +28,7 @@ computer use more power than necessary while it is idle.
|
||||
%patch0 -p1 -b .always-create-params
|
||||
%patch1 -p1 -b .man-fix
|
||||
%patch2 -p1 -b .ondemand-check
|
||||
%patch3 -p1 -b .tunable-overfow-fix
|
||||
|
||||
# remove left over object files
|
||||
find . -name "*.o" -exec rm {} \;
|
||||
@ -59,6 +61,10 @@ rm -rf %{buildroot}
|
||||
%{_mandir}/man8/powertop.8*
|
||||
|
||||
%changelog
|
||||
* Tue Mar 25 2014 Jaroslav Škarvada <jskarvad@redhat.com> - 2.5-2
|
||||
- Fixed buffer overflow in cpufreq tunables on systems with many CPUs
|
||||
(by tunable-overflow-fix patch)
|
||||
|
||||
* Mon Nov 25 2013 Jaroslav Škarvada <jskarvad@redhat.com> - 2.5-1
|
||||
- New version
|
||||
Resolves: rhbz#1034113
|
||||
|
||||
Loading…
Reference in New Issue
Block a user