mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Pratyush Anand <panand@redhat.com>, <stable@vger.kernel.org>
Subject: [PATCH 1/5] seq_buf: Fix seq_buf_vprintf() truncation
Date: Mon, 09 Mar 2015 12:03:54 -0400	[thread overview]
Message-ID: <20150309160546.681326173@goodmis.org> (raw)
In-Reply-To: <20150309160353.065685105@goodmis.org>

[-- Attachment #1: 0001-seq_buf-Fix-seq_buf_vprintf-truncation.patch --]
[-- Type: text/plain, Size: 1878 bytes --]

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

In seq_buf_vprintf(), vsnprintf() is used to copy the format into the
buffer remaining in the seq_buf structure. The return of vsnprintf()
is the amount of characters written to the buffer excluding the '\0',
unless the line was truncated!

If the line copied does not fit, it is truncated, and a '\0' is added
to the end of the buffer. But in this case, '\0' is included in the length
of the line written. To know if the buffer had overflowed, the return
length will be the same as the length of the buffer passed in.

The check in seq_buf_vprintf() only checked if the length returned from
vsnprintf() would fit in the buffer, as the seq_buf_vprintf() is only
to be an all or nothing command. It either writes all the string into
the seq_buf, or none of it. If the string is truncated, the pointers
inside the seq_buf must be reset to what they were when the function was
called. This is not the case. On overflow, it copies only part of the string.

The fix is to change the overflow check to see if the length returned from
vsnprintf() is less than the length remaining in the seq_buf buffer, and not
if it is less than or equal to as it currently does. Then seq_buf_vprintf()
will know if the write from vsnpritnf() was truncated or not.

Cc: stable@vger.kernel.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 lib/seq_buf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/seq_buf.c b/lib/seq_buf.c
index 88c0854bd752..0c92583b7b7e 100644
--- a/lib/seq_buf.c
+++ b/lib/seq_buf.c
@@ -61,7 +61,7 @@ int seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args)
 
 	if (s->len < s->size) {
 		len = vsnprintf(s->buffer + s->len, s->size - s->len, fmt, args);
-		if (seq_buf_can_fit(s, len)) {
+		if (s->len + len < s->size) {
 			s->len += len;
 			return 0;
 		}
-- 
2.1.4



  reply	other threads:[~2015-03-09 16:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-09 16:03 [PATCH 0/5] [GIT PULL] seq-buf/ftrace: Various fixes Steven Rostedt
2015-03-09 16:03 ` Steven Rostedt [this message]
2015-03-09 16:03 ` [PATCH 2/5] seq_buf: Fix seq_buf_bprintf() truncation Steven Rostedt
2015-03-09 16:03 ` [PATCH 3/5] ftrace: Clear REGS_EN and TRAMP_EN flags on disabling record via sysctl Steven Rostedt
2015-03-09 16:03 ` [PATCH 4/5] ftrace: Fix en(dis)able graph caller when en(dis)abling " Steven Rostedt
2015-03-09 16:03 ` [PATCH 5/5] ftrace: Fix ftrace enable ordering of sysctl ftrace_enabled Steven Rostedt
2015-03-10  1:14 ` [PATCH 0/5] [GIT PULL] seq-buf/ftrace: Various fixes Linus Torvalds
2015-03-10  1:36   ` Steven Rostedt
2015-03-10  1:43     ` Linus Torvalds
2015-03-10  2:03       ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150309160546.681326173@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=panand@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome