public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Miao Xie <miaox@cn.fujitsu.com>
To: WANG Cong <xiyou.wangcong@gmail.com>
Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] time: fix sysfs_show_{available,current}_clocksources() buffer overflow problem
Date: Sun, 11 Nov 2007 11:29:59 +0800	[thread overview]
Message-ID: <47367737.8030901@cn.fujitsu.com> (raw)
In-Reply-To: <20071108121117.GG2479@hacking>

on 2007-11-8 20:11 WANG Cong wrote:
> On Thu, Nov 08, 2007 at 07:47:41PM +0800, WANG Cong wrote:
>> Yes, snprintf is safer than sprintf. But here, the 'count' will be
>> mis-pointed when snprintf returns no less than PAGE_SIZE (what you called
>> overflow). So you may also need:
>>
>> 	if (unlikely(count >= PAGE_SIZE))
>> 		count = PAGE_SIZE - 1;
>>
>> Just a simple guess. ;)
> 
> Or try scnprintf. ;)

We have discussed this problem. We think that it is better to return the return
value of kernel directly because this is the specification of the sysfs.

   (Version:2.6.24-rc2,File:Documentation/filesystems/sysfs.txt:198-201):
   198 - show() methods should return the number of bytes printed into the
   199   buffer. This is the return value of snprintf().
   200
   201 - show() should always use snprintf().

And the function which calls the show() methods uses BUG_ON() to check the
return value. If the return value is too big,it means something wrong.

If we use scnprintf, we may not know whether the resulting string is truncated
or not. Maybe A big bug is ignored.


  reply	other threads:[~2007-11-11  3:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-08 10:53 [PATCH] time: fix sysfs_show_{available,current}_clocksources() buffer overflow problem Miao Xie
2007-11-08 11:47 ` WANG Cong
2007-11-08 12:11   ` WANG Cong
2007-11-11  3:29     ` Miao Xie [this message]
2007-11-11  4:09       ` WANG Cong

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=47367737.8030901@cn.fujitsu.com \
    --to=miaox@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=xiyou.wangcong@gmail.com \
    /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