linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] pstore/ram: no timekeeping calls when unavailable
@ 2012-11-05 22:00 Kees Cook
  2012-11-10  0:56 ` John Stultz
  0 siblings, 1 reply; 10+ messages in thread
From: Kees Cook @ 2012-11-05 22:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: Anton Vorontsov, Colin Cross, Kees Cook, Tony Luck, John Stultz,
	Thomas Gleixner

We must not call timekeeping functions unless they are available. If we dump
before they have resumed, avoid a WARN_ON by setting the timestamp to 0.

Since the "ram" pstore driver can be a module, we must have
timekeeping_suspended exported.

Reported-by: Doug Anderson <dianders@chromium.org>
Cc: Anton Vorontsov <cbouatmailru@gmail.com>
Cc: John Stultz <johnstul@us.ibm.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
v2:
 - export needed for timekeeping_suspended (thanks to Fengguang Wu).
---
 fs/pstore/ram.c           |    8 +++++++-
 kernel/time/timekeeping.c |    1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 1a4f6da..6d014e0 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -171,7 +171,13 @@ static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz)
 	struct timeval timestamp;
 	size_t len;
 
-	do_gettimeofday(&timestamp);
+	/* Handle dumping before timekeeping has resumed. */
+	if (unlikely(timekeeping_suspended)) {
+		timestamp.tv_sec = 0;
+		timestamp.tv_usec = 0;
+	} else
+		do_gettimeofday(&timestamp);
+
 	hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
 		(long)timestamp.tv_sec, (long)timestamp.tv_usec);
 	WARN_ON_ONCE(!hdr);
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index e424970..24ea968 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -33,6 +33,7 @@ __cacheline_aligned_in_smp DEFINE_SEQLOCK(xtime_lock);
 
 /* flag for if timekeeping is suspended */
 int __read_mostly timekeeping_suspended;
+EXPORT_SYMBOL_GPL(timekeeping_suspended);
 
 static inline void tk_normalize_xtime(struct timekeeper *tk)
 {
-- 
1.7.9.5


-- 
Kees Cook
Chrome OS Security

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-11-19 21:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-05 22:00 [PATCH v2] pstore/ram: no timekeeping calls when unavailable Kees Cook
2012-11-10  0:56 ` John Stultz
2012-11-10  1:26   ` Kees Cook
2012-11-17  2:53     ` Anton Vorontsov
2012-11-17  3:16       ` John Stultz
2012-11-18 20:09         ` Kees Cook
2012-11-19 17:23           ` John Stultz
2012-11-19 17:45             ` Kees Cook
2012-11-19 18:57               ` John Stultz
2012-11-19 21:42                 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).