Blame SOURCES/quota-4.01-Prevent-from-grace-period-overflow-in-RPC-transport.patch

e40344
From d850a85b2374fe1b83779c0fc61463057eeca4ab Mon Sep 17 00:00:00 2001
e40344
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
e40344
Date: Mon, 24 Feb 2014 15:54:32 +0100
e40344
Subject: [PATCH] Prevent from grace period overflow in RPC transport
e40344
MIME-Version: 1.0
e40344
Content-Type: text/plain; charset=UTF-8
e40344
Content-Transfer-Encoding: 8bit
e40344
e40344
The RPC transports grace time as unsigned int, but the value stored
e40344
there and retrivedd from is treated as singed difference against current time.
e40344
e40344
This leads to overflow after expiring the grace time which is
e40344
presented as an enourmously large grace time instead of "none" in the
e40344
quota(1) output.
e40344
e40344
There also possible an overflow when the time difference is still
e40344
bigger than an int can represent.
e40344
e40344
This first issue is solved by explicit type cast to/from int32_t, the
e40344
second issue is fixes by limiting the value into int32_t range.
e40344
e40344
<https://sourceforge.net/p/linuxquota/bugs/115/>
e40344
e40344
Signed-off-by: Petr Písař <ppisar@redhat.com>
e40344
Signed-off-by: Jan Kara <jack@suse.cz>
e40344
---
e40344
 quotasys.c      | 13 +++++++++++++
e40344
 quotasys.h      |  4 ++++
e40344
 rquota_client.c | 10 ++++++----
e40344
 rquota_server.c |  9 +++++----
e40344
 4 files changed, 28 insertions(+), 8 deletions(-)
e40344
e40344
diff --git a/quotasys.c b/quotasys.c
e40344
index 120125a..a5737a8 100644
e40344
--- a/quotasys.c
e40344
+++ b/quotasys.c
e40344
@@ -23,6 +23,7 @@
e40344
 #include <sys/types.h>
e40344
 #include <sys/stat.h>
e40344
 #include <sys/vfs.h>
e40344
+#include <stdint.h>
e40344
 
e40344
 #include "pot.h"
e40344
 #include "bylabel.h"
e40344
@@ -323,6 +324,18 @@ void difftime2str(time_t seconds, char *buf)
e40344
 }
e40344
 
e40344
 /*
e40344
+ * Round difference of two time_t values into int32_t
e40344
+ */
e40344
+int32_t difftime2net(time_t later, time_t sooner)
e40344
+{
e40344
+	if ((later - sooner) > INT32_MAX)
e40344
+		return INT32_MAX;
e40344
+	if ((later - sooner) < INT32_MIN)
e40344
+		return INT32_MIN;
e40344
+	return (later - sooner);
e40344
+}
e40344
+
e40344
+/*
e40344
  * Convert time to printable form
e40344
  */
e40344
 void time2str(time_t seconds, char *buf, int flags)
e40344
diff --git a/quotasys.h b/quotasys.h
e40344
index e79f8cd..d8d79fe 100644
e40344
--- a/quotasys.h
e40344
+++ b/quotasys.h
e40344
@@ -8,6 +8,7 @@
e40344
 #define GUARD_QUOTASYS_H
e40344
 
e40344
 #include <sys/types.h>
e40344
+#include <inttypes.h>
e40344
 #include "mntopt.h"
e40344
 #include "quota.h"
e40344
 
e40344
@@ -100,6 +101,9 @@ int util2kernfmt(int fmt);
e40344
 /* Convert time difference between given time and current time to printable form */
e40344
 void difftime2str(time_t, char *);
e40344
 
e40344
+/* Round difference of two time_t values into int32_t */
e40344
+int32_t difftime2net(time_t later, time_t sooner);
e40344
+
e40344
 /* Convert time to printable form */
e40344
 void time2str(time_t, char *, int);
e40344
 
e40344
diff --git a/rquota_client.c b/rquota_client.c
e40344
index e26e066..9d4055e 100644
e40344
--- a/rquota_client.c
e40344
+++ b/rquota_client.c
e40344
@@ -32,11 +32,13 @@
e40344
 #include <string.h>
e40344
 #include <signal.h>
e40344
 #include <time.h>
e40344
+#include <stdint.h>
e40344
 
e40344
 #include "mntopt.h"
e40344
 #include "rquota.h"
e40344
 #include "common.h"
e40344
 #include "quotaio.h"
e40344
+#include "quotasys.h"
e40344
 
e40344
 #if defined(RPC)
e40344
 
e40344
@@ -54,11 +56,11 @@ static inline void clinet2utildqblk(struct util_dqblk *u, struct rquota *n)
e40344
 	u->dqb_curspace = ((qsize_t)n->rq_curblocks) * n->rq_bsize;
e40344
 	time(&now;;
e40344
 	if (n->rq_btimeleft)
e40344
-		u->dqb_btime = n->rq_btimeleft + now;
e40344
+		u->dqb_btime = (int32_t)n->rq_btimeleft + now;
e40344
 	else
e40344
 		u->dqb_btime = 0;
e40344
 	if (n->rq_ftimeleft)
e40344
-		u->dqb_itime = n->rq_ftimeleft + now;
e40344
+		u->dqb_itime = (int32_t)n->rq_ftimeleft + now;
e40344
 	else
e40344
 		u->dqb_itime = 0;
e40344
 }
e40344
@@ -76,11 +78,11 @@ static inline void cliutil2netdqblk(struct sq_dqblk *n, struct util_dqblk *u)
e40344
 	n->rq_curblocks = toqb(u->dqb_curspace);
e40344
 	n->rq_curfiles = u->dqb_curinodes;
e40344
 	if (u->dqb_btime)
e40344
-		n->rq_btimeleft = u->dqb_btime - now;
e40344
+		n->rq_btimeleft = difftime2net(u->dqb_btime, now);
e40344
 	else
e40344
 		n->rq_btimeleft = 0;
e40344
 	if (u->dqb_itime)
e40344
-		n->rq_ftimeleft = u->dqb_itime - now;
e40344
+		n->rq_ftimeleft = difftime2net(u->dqb_itime, now);
e40344
 	else
e40344
 		n->rq_ftimeleft = 0;
e40344
 }
e40344
diff --git a/rquota_server.c b/rquota_server.c
e40344
index bf66e4d..09cf6ed 100644
e40344
--- a/rquota_server.c
e40344
+++ b/rquota_server.c
e40344
@@ -25,6 +25,7 @@
e40344
 #include <stdio.h>
e40344
 #include <syslog.h>
e40344
 #include <time.h>
e40344
+#include <stdint.h>
e40344
 
e40344
 #include "mntopt.h"
e40344
 #include "quotaops.h"
e40344
@@ -82,11 +83,11 @@ static inline void servnet2utildqblk(struct util_dqblk *u, sq_dqblk * n)
e40344
 	u->dqb_curspace = ((qsize_t)n->rq_curblocks) << RPC_DQBLK_SIZE_BITS;
e40344
 	u->dqb_curinodes = n->rq_curfiles;
e40344
 	if (n->rq_btimeleft)
e40344
-		u->dqb_btime = n->rq_btimeleft + now;
e40344
+		u->dqb_btime = (int32_t)n->rq_btimeleft + now;
e40344
 	else
e40344
 		u->dqb_btime = 0;
e40344
 	if (n->rq_ftimeleft)
e40344
-		u->dqb_itime = n->rq_ftimeleft + now;
e40344
+		u->dqb_itime = (int32_t)n->rq_ftimeleft + now;
e40344
 	else
e40344
 		u->dqb_itime = 0;
e40344
 }
e40344
@@ -127,11 +128,11 @@ static inline void servutil2netdqblk(struct rquota *n, struct util_dqblk *u)
e40344
 
e40344
 	time(&now;;
e40344
 	if (u->dqb_btime)
e40344
-		n->rq_btimeleft = u->dqb_btime - now;
e40344
+		n->rq_btimeleft = difftime2net(u->dqb_btime, now);
e40344
 	else
e40344
 		n->rq_btimeleft = 0;
e40344
 	if (u->dqb_itime)
e40344
-		n->rq_ftimeleft = u->dqb_itime - now;
e40344
+		n->rq_ftimeleft = difftime2net(u->dqb_itime, now);
e40344
 	else
e40344
 		n->rq_ftimeleft = 0;
e40344
 }
e40344
-- 
e40344
2.5.0
e40344