linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] Fix off-by-one in pass_env_to_socket()
Date: Mon, 08 Sep 2008 13:17:05 +0000	[thread overview]
Message-ID: <48C525D1.9050401@tuffmail.co.uk> (raw)

This only manifests in exceptional circumstances when the variables exceed
the buffer size.  It can be reproduced as follows:

[kill existing udevd and udevadm]

valgrind -q ./udevd & sleep 1

LONG=`dd if=/dev/zero bs=1 countP0 | tr '\0' 'A'` # 500 character string
for VAR in a b c d; do
	./udevadm control --env $VAR=$LONG
done

./udevadm monitor -e > /dev/null &
./udevadm trigger

[wait a few seconds]

=17942= Syscall param socketcall.sendto(msg) points to uninitialised byte(s)
=17942=    at 0x511BBC3: __sendto_nocancel (in /usr/lib/debug/libc-2.7.so)
=17942=    by 0x407B72: pass_env_to_socket (udev_rules.c:500)
=17942=    by 0x407C7F: udev_rules_run (udev_rules.c:517)
=17942=    by 0x410DDB: udev_event_process (udevd.c:145)
=17942=    by 0x411217: udev_event_run (udevd.c:251)
=17942=    by 0x411E78: msg_queue_manager (udevd.c:581)
=17942=    by 0x413C10: main (udevd.c:1282)
=17942=  Address 0x7fefff0af is on thread 1's stack
...

kill %1 %2

[restart normal udevd]

diff --git a/udev/udev_rules.c b/udev/udev_rules.c
index f372a61..9ed4d62 100644
--- a/udev/udev_rules.c
+++ b/udev/udev_rules.c
@@ -490,8 +490,8 @@ static int pass_env_to_socket(const char *sockpath, const char *devpath, const c
 
 	bufpos = snprintf(buf, sizeof(buf)-1, "%s@%s", action, devpath);
 	bufpos++;
-	for (i = 0; environ[i] != NULL && bufpos < (sizeof(buf)-1); i++) {
-		bufpos += strlcpy(&buf[bufpos], environ[i], sizeof(buf) - bufpos-1);
+	for (i = 0; environ[i] != NULL && bufpos < sizeof(buf); i++) {
+		bufpos += strlcpy(&buf[bufpos], environ[i], sizeof(buf) - bufpos);
 		bufpos++;
 	}
 	if (bufpos > sizeof(buf))



             reply	other threads:[~2008-09-08 13:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-08 13:17 Alan Jenkins [this message]
2008-09-08 22:40 ` [PATCH] Fix off-by-one in pass_env_to_socket() Kay Sievers

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=48C525D1.9050401@tuffmail.co.uk \
    --to=alan-jenkins@tuffmail.co.uk \
    --cc=linux-hotplug@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;
as well as URLs for NNTP newsgroup(s).