linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel K." <dk@uw.no>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: "Daniel K." <dk@uw.no>, Jesper Juhl <jj@chaosbits.net>,
	linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org,
	Neil Brown <neilb@suse.de>, Neil Brown <neilb@cse.unsw.edu.au>
Subject: Re: [PATCH] md: Remove risk of overflow via sprintf) by using snprintf() in md_check_recovery()
Date: Sat, 12 Feb 2011 14:06:31 +0000	[thread overview]
Message-ID: <4D5693E7.2010000@uw.no> (raw)
In-Reply-To: <4D568FCA.90902@msgid.tls.msk.ru>

Michael Tokarev wrote:
> 12.02.2011 12:34, Daniel K. wrote:
>> Jesper Juhl wrote:
>>> sprintf() is dangerous - given the wrong source string it will
>>> overflow the destination. snprintf() is safer in that at least we'll
>>> never overflow the destination. Even if overflow will never happen
>>> today, code changes over time and snprintf() is just safer in the long
>>> run.
>>> -                        sprintf(nm,"rd%d", rdev->raid_disk);
>>> +                        snprintf(nm, sizeof(nm), "rd%d", rdev->raid_disk);
>>>                          sysfs_remove_link(&mddev->kobj, nm);
>> What if "rd1234" get truncated to "rd123" and you remove the wrong link.
>> (No, I didn't actually bother to check how much room was allocated.)
> 
> That allocation is in the line above first sprintf which you deleted.
> Sure, didn't bother, it's very difficult.

Yeah, early morning, I cut to much, and I didn't bother to look it up 
again, sorry for being lazy. Nevertheless, the actual size is of the 
allocation is of no particular importance. As you've shown, the current 
allocation of 20 bytes is more than enough.

> C'mon guys, this is pointless.  20 bytes allocated for the device
> name, and this is for raid disk number.  It is impossible to have
> more than 10^17 (20 bytes total, 2 for "rd" and on for the zero
> terminator) drives in a single array.

Agreed, and this was sort of the point.

In all probability it would not overflow, and if it did, it would be 
better for it to crash and burn, than to unlink the wrong files.


Daniel K.

  reply	other threads:[~2011-02-12 14:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-11 21:30 [PATCH] md: Remove risk of overflow via sprintf) by using snprintf() in md_check_recovery() Jesper Juhl
2011-02-12  9:34 ` Daniel K.
2011-02-12 13:48   ` Michael Tokarev
2011-02-12 14:06     ` Daniel K. [this message]
2011-02-13 20:18       ` Jesper Juhl
     [not found] <gl8SB-1hb-11@gated-at.bofh.it>
     [not found] ` <glk7o-3l2-17@gated-at.bofh.it>
     [not found]   ` <glo1k-1AX-17@gated-at.bofh.it>
2011-02-13 20:53     ` Bodo Eggert

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=4D5693E7.2010000@uw.no \
    --to=dk@uw.no \
    --cc=jj@chaosbits.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=mjt@tls.msk.ru \
    --cc=neilb@cse.unsw.edu.au \
    --cc=neilb@suse.de \
    /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).