1
0
forked from pool/util-linux

Accepting request 234890 from Base:System

squashed sr234195  and re-submitted

- Prevent excessive clock drift calculations (bnc#871698,
  util-linux-prevent-excessive-clock-drift-calculations.patch),
  committed by sbrabec@suse.cz (forwarded request 234334 from rudi_m)

OBS-URL: https://build.opensuse.org/request/show/234890
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/util-linux?expand=0&rev=186
This commit is contained in:
Stephan Kulow 2014-05-22 18:38:39 +00:00 committed by Git OBS Bridge
commit 3e68913fe8
5 changed files with 344 additions and 10 deletions

View File

@ -1,14 +1,21 @@
Be aware that on s390 the 3270 terminal line is found at
/dev/3270/tty<X>. That is that the baud speed rate numbers
have to be identified in a unique way.
---
agetty.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
login-utils/sulogin.c | 8 +++++++-
term-utils/agetty.c | 15 ++++++++++-----
2 files changed, 17 insertions(+), 6 deletions(-)
--- term-utils/agetty.c
+++ term-utils/agetty.c 2014-02-04 09:33:13.162735763 +0000
@@ -568,6 +568,8 @@ static void login_options_to_argv(char *
+++ term-utils/agetty.c 2014-05-08 08:08:26.384484940 +0000
@@ -51,7 +51,8 @@
# define DEFAULT_VCTERM "linux"
# endif
# if defined (__s390__) || defined (__s390x__)
-# define DEFAULT_TTYS0 "ibm327x"
+# define DEFAULT_TTYS0 "dumb"
+# define DEFAULT_TTY32 "ibm327x"
# define DEFAULT_TTYS1 "vt220"
# endif
# ifndef DEFAULT_STERM
@@ -571,6 +572,8 @@ static void login_options_to_argv(char *
*argc = i;
}
@ -17,7 +24,7 @@ have to be identified in a unique way.
/* Parse command-line arguments. */
static void parse_args(int argc, char **argv, struct options *op)
{
@@ -746,7 +748,7 @@ static void parse_args(int argc, char **
@@ -749,7 +752,7 @@ static void parse_args(int argc, char **
}
/* Accept "tty", "baudrate tty", and "tty baudrate". */
@ -26,7 +33,7 @@ have to be identified in a unique way.
/* Assume BSD style speed. */
parse_speeds(op, argv[optind++]);
if (argc < optind + 1) {
@@ -758,7 +760,7 @@ static void parse_args(int argc, char **
@@ -761,7 +764,7 @@ static void parse_args(int argc, char **
op->tty = argv[optind++];
if (argc > optind) {
char *v = argv[optind++];
@ -35,3 +42,37 @@ have to be identified in a unique way.
parse_speeds(op, v);
else
op->speeds[op->numspeed++] = bcode("9600");
@@ -1071,9 +1074,11 @@ static void open_tty(char *tty, struct t
* higher. Whereas the second serial line on a S/390(x) is
* a real character terminal which is compatible with VT220.
*/
- if (strcmp(op->tty, "ttyS0") == 0)
+ if (strcmp(op->tty, "ttyS0") == 0) /* linux/drivers/s390/char/con3215.c */
op->term = DEFAULT_TTYS0;
- else if (strcmp(op->tty, "ttyS1") == 0)
+ else if (strncmp(op->tty, "3270/tty", 8) == 0) /* linux/drivers/s390/char/con3270.c */
+ op->term = DEFAULT_TTY32;
+ else if (strcmp(op->tty, "ttyS1") == 0) /* linux/drivers/s390/char/sclp_vt220.c */
op->term = DEFAULT_TTYS1;
}
#endif
--- login-utils/sulogin.c
+++ login-utils/sulogin.c 2014-05-08 08:22:38.572781002 +0000
@@ -189,10 +189,16 @@ static void tcfinal(struct console *con)
setenv("TERM", "linux", 1);
return;
}
- if (con->flags & CON_NOTTY)
+ if (con->flags & CON_NOTTY) {
+ setenv("TERM", "dumb", 1);
return;
+ }
+#if defined (__s390__) || defined (__s390x__)
+ setenv("TERM", "dumb", 1);
+#else
setenv("TERM", "vt102", 1);
+#endif
tio = &con->tio;
fd = con->fd;

View File

@ -0,0 +1,104 @@
---
login-utils/sulogin.c | 17 ++++++++++++-----
term-utils/agetty.c | 23 +++++++++++------------
2 files changed, 23 insertions(+), 17 deletions(-)
--- login-utils/sulogin.c
+++ login-utils/sulogin.c 2014-05-08 08:01:13.102622002 +0000
@@ -49,6 +49,11 @@
# include <selinux/get_context_list.h>
#endif
+#ifdef __linux__
+# include <sys/kd.h>
+# include <sys/param.h>
+#endif
+
#include "c.h"
#include "closestream.h"
#include "nls.h"
@@ -142,10 +147,14 @@ static void tcinit(struct console *con)
return;
}
- /* Handle serial lines here */
- if (ioctl(fd, TIOCMGET, (char *) &mode) == 0) {
+ /* Handle lines other than virtual consoles here */
+#if defined(KDGKBMODE)
+ if (ioctl(fd, KDGKBMODE, &mode) < 0)
+#endif
+ {
speed_t ispeed, ospeed;
struct winsize ws;
+ errno = 0;
/* this is a modem line */
con->flags |= CON_SERIAL;
@@ -191,9 +200,7 @@ static void tcinit(struct console *con)
goto setattr;
}
#if defined(IUTF8) && defined(KDGKBMODE)
- /* Detect mode of current keyboard setup, e.g. for UTF-8 */
- if (ioctl(fd, KDGKBMODE, &mode) < 0)
- mode = K_RAW;
+ /* Handle mode of current keyboard setup, e.g. for UTF-8 */
switch(mode) {
case K_UNICODE:
setlocale(LC_CTYPE, "C.UTF-8");
--- term-utils/agetty.c
+++ term-utils/agetty.c 2014-05-08 08:02:16.786235584 +0000
@@ -139,6 +139,7 @@ struct options {
int nice; /* Run login with this priority */
int numspeed; /* number of baud rates to try */
int clocal; /* CLOCAL_MODE_* */
+ int kbmode; /* Keyboard mode if virtual console */
speed_t speeds[MAX_SPEED]; /* baud rates to be tried */
};
@@ -936,7 +937,7 @@ static void update_utmp(struct options *
static void open_tty(char *tty, struct termios *tp, struct options *op)
{
const pid_t pid = getpid();
- int serial, closed = 0;
+ int closed = 0;
/* Set up new standard input, unless we are given an already opened port. */
@@ -1080,15 +1081,18 @@ static void open_tty(char *tty, struct t
#endif
/*
* Detect if this is a virtual console or serial/modem line.
- * In case of a virtual console the ioctl TIOCMGET fails and
- * the error number will be set to EINVAL.
+ * In case of a virtual console the ioctl KDGKBMODE succeeds
+ * whereas on other lines it will fails.
*/
- if (ioctl(STDIN_FILENO, TIOCMGET, &serial) < 0 && (errno == EINVAL)) {
+ if (ioctl(STDIN_FILENO, KDGKBMODE, &op->kbmode) == 0) {
op->flags |= F_VCONSOLE;
if (!op->term)
op->term = DEFAULT_VCTERM;
- } else if (!op->term)
- op->term = DEFAULT_STERM;
+ } else {
+ op->kbmode = K_RAW;
+ if (!op->term)
+ op->term = DEFAULT_STERM;
+ }
setenv("TERM", op->term, 1);
}
@@ -1122,12 +1126,7 @@ static void termio_init(struct options *
if (op->flags & F_VCONSOLE) {
#if defined(IUTF8) && defined(KDGKBMODE)
- int mode;
-
- /* Detect mode of current keyboard setup, e.g. for UTF-8 */
- if (ioctl(STDIN_FILENO, KDGKBMODE, &mode) < 0)
- mode = K_RAW;
- switch(mode) {
+ switch(op->kbmode) {
case K_UNICODE:
setlocale(LC_CTYPE, "C.UTF-8");
op->flags |= F_UTF8;

View File

@ -0,0 +1,162 @@
From 654e902731ea15a3494a3831b78d2b9f1cd1408d Mon Sep 17 00:00:00 2001
From: Ruediger Meier <ruediger.meier@ga-group.nl>
Date: Fri, 16 May 2014 17:01:43 +0200
Subject: [PATCH] Prevent excessive clock drift calculations
Squashed commit of the following:
commit f55b4b45126b657fe02f5f0d3d7fde740e6a6247
Author: Karel Zak <kzak@redhat.com>
Date: Tue May 6 12:51:42 2014 +0200
hwclock: fix typo
Reported-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
commit db8fc5f37728810bdd5b865ac420c31714e35def
Author: Stanislav Brabec <sbrabec@suse.cz>
Date: Mon May 5 20:49:49 2014 +0200
hwclock: Check drift value in /etc/adjtime
Due to bug in older versions of hwclock, /etc/adjtime can contain
excessive drift value (up to many years per day). Prevent it
from applying.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
commit f196fd1a5f8fff63635fd88b5a0f0bbc96978df2
Author: Stanislav Brabec <sbrabec@suse.cz>
Date: Mon May 5 20:49:29 2014 +0200
hwclock: Prevent excessive drift values
Failure of CMOS battery can cause writing of excessive drift
values (up to many years per day).
This causes excessive hwclock adjustment next time, which may lead
to overflow in calculate_adjustment() (and hang before 4a44a54b).
Prevent this situation, check drift for limits and reset drift to zero
instead.
Steps to reproduce:
mv /etc/adjtime /etc/adjtime.backup
rm /etc/adjtime
hwclock --set --date 2001-01-01\ 01:00:00
changing of /etc/adjtime.
mv /etc/adjtime /etc/adjtime.saved
hwclock --set --date 2001-01-02\ 01:00:01
mv /etc/adjtime.saved /etc/adjtime
echo "======= The /etc/adjtime has a \"correct\" look:"
cat /etc/adjtime
hwclock --debug --systohc --utc
echo "======= The /etc/adjtime now has deeply failed drift value:"
cat /etc/adjtime
mv /etc/adjtime /etc/adjtime.saved
hwclock --set --date 2015-01-01\ 01:00:00
mv /etc/adjtime.saved /etc/adjtime
hwclock --debug --adjust
echo "======= And the last /etc/adjtime:"
cat /etc/adjtime
mv /etc/adjtime.backup /etc/adjtime
hwclock --systohc --utc
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
sys-utils/hwclock.c | 47 ++++++++++++++++++++++++++++++++++-------------
1 file changed, 34 insertions(+), 13 deletions(-)
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index 395b5c3..0abf01f 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -91,6 +91,11 @@ struct clock_ops *ur;
#define FLOOR(arg) ((arg >= 0 ? (int) arg : ((int) arg) - 1));
+/* Maximal clock adjustment in seconds per day.
+ (adjtime() glibc call has 2145 seconds limit on i386, so it is good enough for us as well,
+ 43219 is a maximal safe value preventing exact_adjustment overflow.) */
+#define MAX_DRIFT 2145.0
+
const char *adj_file_name = NULL;
struct adjtime {
@@ -1008,6 +1013,7 @@ adjust_drift_factor(struct adjtime *adjtime_p,
double adj_days, cal_days;
double exp_drift, unc_drift;
double factor_adjust;
+ double drift_factor;
/* Adjusted time units per hardware time unit */
atime_per_htime = 1.0 + adjtime_p->drift_factor / sec_per_day;
@@ -1033,16 +1039,28 @@ adjust_drift_factor(struct adjtime *adjtime_p,
/* Amount to add to previous drift factor */
factor_adjust = unc_drift / cal_days;
- if (debug)
- printf(_("Clock drifted %.1f seconds in the past "
- "%d seconds in spite of a drift factor of "
- "%f seconds/day.\n"
- "Adjusting drift factor by %f seconds/day\n"),
- unc_drift,
- (int)(nowtime - adjtime_p->last_calib_time),
- adjtime_p->drift_factor, factor_adjust);
-
- adjtime_p->drift_factor += factor_adjust;
+ /* New drift factor */
+ drift_factor = adjtime_p->drift_factor + factor_adjust;
+
+ if (abs(drift_factor) > MAX_DRIFT) {
+ if (debug)
+ printf(_("Clock drift factor was calculated as "
+ "%f seconds/day.\n"
+ "It is far too much. Resetting to zero.\n"),
+ drift_factor);
+ drift_factor = 0;
+ } else {
+ if (debug)
+ printf(_("Clock drifted %.1f seconds in the past "
+ "%d seconds in spite of a drift factor of "
+ "%f seconds/day.\n"
+ "Adjusting drift factor by %f seconds/day\n"),
+ unc_drift,
+ (int)(nowtime - adjtime_p->last_calib_time),
+ adjtime_p->drift_factor, factor_adjust);
+ }
+
+ adjtime_p->drift_factor = drift_factor;
}
adjtime_p->last_calib_time = nowtime;
@@ -1190,9 +1208,12 @@ do_adjustment(struct adjtime *adjtime_p,
adjtime_p->dirty = TRUE;
} else if (adjtime_p->last_adj_time == 0) {
if (debug)
- printf(_
- ("Not setting clock because last adjustment time is zero, "
- "so history is bad."));
+ printf(_("Not setting clock because last adjustment time is zero, "
+ "so history is bad.\n"));
+ } else if (abs(adjtime_p->drift_factor) > MAX_DRIFT) {
+ if (debug)
+ printf(_("Not setting clock because drift factor %f is far too high.\n"),
+ adjtime_p->drift_factor);
} else {
int adjustment;
/* Number of seconds we must insert in the Hardware Clock */
--
1.8.4.5

View File

@ -1,3 +1,24 @@
-------------------------------------------------------------------
Fri May 16 15:10:53 UTC 2014 - sweet_f_a@gmx.de
- Prevent excessive clock drift calculations (bnc#871698,
util-linux-prevent-excessive-clock-drift-calculations.patch),
committed by sbrabec@suse.cz
-------------------------------------------------------------------
Thu May 8 08:15:04 UTC 2014 - werner@suse.de
- Modify patch support-other-tty-lines-not-vconsole.patch to
make it work on virtual console
- Modify patch agetty-on-s390-on-dev-3270-tty1-line.patch
to add the missed 3270 support upstream
-------------------------------------------------------------------
Wed May 7 14:12:32 UTC 2014 - werner@suse.de
- Add patch support-other-tty-lines-not-vconsole.patch
to be able to support console lines like xvc and hvc
-------------------------------------------------------------------
Thu Apr 24 11:33:36 UTC 2014 - sweet_f_a@gmx.de

View File

@ -104,6 +104,8 @@ Patch2: util-linux-2.23.1-eject-fpie.patch
Patch4: make-sure-sbin-resp-usr-sbin-are-in-PATH.diff
# disable encryption
Patch12: util-linux-2.23.1-noenc-suse.diff
# PATCH-FIX-SUSE Be aware that there are e.g. xvc/hvc
Patch14: support-other-tty-lines-not-vconsole.patch
# PATCH-FIX-SUSE -- Let agetty not be fooled by locked termios srtucture
Patch15: agetty-fooled-on-serial-line-due-plymouth.patch
# PATCH-FIX-SUSE -- Let agetty detect /dev/3270/tty1 as device not as baud rate
@ -126,6 +128,8 @@ Patch30: blkid-stop-scanning-on-I-O-error.patch
Patch31: blkid-convert-superblocks-to-new-calling-convention.patch
# PATH-FIX-UPSTREAM util-linux-libblkid-ext-probe.patch bnc864703 sbrabec@suse.cz -- libblkid: Drop the broken ext2/ext3/ext4 discrimination logic.
Patch32: util-linux-libblkid-ext-probe.patch
# PATCH-FIX-UPSTREAM bnc871698 sbrabec@suse.cz
Patch33: util-linux-prevent-excessive-clock-drift-calculations.patch
##
## klogconsole
@ -247,6 +251,7 @@ xzcat %{S:0} | %gpg_verify %{S:12} -
%patch2 -p1
%patch4 -p1
%patch12 -p1
%patch14 -p0
%patch15 -p0
%patch16 -p0
%patch17 -p0
@ -260,6 +265,7 @@ xzcat %{S:0} | %gpg_verify %{S:12} -
%patch30 -p1
%patch31 -p1
%patch32 -p1
%patch33 -p1
#
# setctsid
cp -p %{S:22} %{S:23} .