mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tom Zanussi <zanussi@us.ibm.com>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 2.6.12-rc1-mm2] relayfs: properly handle oversized events
Date: Thu, 24 Mar 2005 16:00:55 -0600	[thread overview]
Message-ID: <16963.14487.752842.849000@tut.ibm.com> (raw)

This patch fails writes larger than the sub-buffer size and prints a
warning and stack trace when it happens.  I chose this over BUG_ON()
or silently failing since while it could probably be considered a bug
for an application to let this happen, it's not fatal and the user
would probably want to know (and change buffer sizes).

Andrew, please apply.

Thanks,

Tom

Signed-off-by: Tom Zanussi <zanussi@us.ibm.com>

diff -urpN -X dontdiff linux-2.6.12-rc1-mm2/fs/relayfs/relay.c linux-2.6.12-rc1-mm2-cur/fs/relayfs/relay.c
--- linux-2.6.12-rc1-mm2/fs/relayfs/relay.c	2005-03-20 22:26:47.000000000 -0600
+++ linux-2.6.12-rc1-mm2-cur/fs/relayfs/relay.c	2005-03-20 23:32:50.000000000 -0600
@@ -378,7 +378,10 @@ unsigned relay_switch_subbuf(struct rcha
 	int new, old, produced = atomic_read(&buf->subbufs_produced);
 	unsigned padding;
 
-	if (atomic_read(&buf->unfull)) {
+	if (unlikely(length > buf->chan->subbuf_size))
+		goto toobig;
+
+	if (unlikely(atomic_read(&buf->unfull))) {
 		atomic_set(&buf->unfull, 0);
 		new = produced % buf->chan->n_subbufs;
 		old = (produced - 1) % buf->chan->n_subbufs;
@@ -410,7 +413,15 @@ unsigned relay_switch_subbuf(struct rcha
 	new = (produced + 1) % buf->chan->n_subbufs;
 	do_switch(buf, new, old);
 
+	if (unlikely(length + buf->offset > buf->chan->subbuf_size))
+		goto toobig;
+
 	return length;
+
+toobig:
+	printk(KERN_WARNING "relayfs: event too large (%u)\n", length);
+	WARN_ON(1);
+	return 0;
 }
 
 /**



                 reply	other threads:[~2005-03-24 22:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=16963.14487.752842.849000@tut.ibm.com \
    --to=zanussi@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®