mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Vladimir Zapolskiy <vz@mleia.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fs: sysfs: don't pass count == 0 to bin file readers
Date: Thu, 21 May 2015 18:14:23 -0400	[thread overview]
Message-ID: <20150521221423.GK4914@htj.duckdns.org> (raw)
In-Reply-To: <1432243276-27733-1-git-send-email-vz@mleia.com>

Hello,

On Fri, May 22, 2015 at 12:21:16AM +0300, Vladimir Zapolskiy wrote:
> If count == 0 bytes are requested by a reader, sysfs_kf_bin_read()
> deliberately returns 0 without passing a potentially harmful value to
> some externally defined underlying battr->read() function.
> 
> However in case of (pos == size && count) the next clause always sets
> count to 0 and this value is handed over to battr->read().
> 
> The change intends to make obsolete (and remove later) a redundant
> sanity check in battr->read(), if it is present, or add more
> protection to struct bin_attribute users, who does not care about
> input arguments.
> 
> Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
> ---
>  fs/sysfs/file.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
> index 7c2867b..6c95628 100644
> --- a/fs/sysfs/file.c
> +++ b/fs/sysfs/file.c
> @@ -90,7 +90,7 @@ static ssize_t sysfs_kf_bin_read(struct kernfs_open_file *of, char *buf,
>  		return 0;
>  
>  	if (size) {
> -		if (pos > size)
> +		if (pos >= size)
>  			return 0;
>  		if (pos + count > size)
>  			count = size - pos;

Hmmm... maybe just move that test upwards?

	if (!count || pos >= size)
		return 0;

	count = min(count, size - pos);

-- 
tejun

  reply	other threads:[~2015-05-21 22:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-21 21:21 Vladimir Zapolskiy
2015-05-21 22:14 ` Tejun Heo [this message]
2015-05-21 23:04   ` Vladimir Zapolskiy
2015-05-21 23:26     ` Tejun Heo
2015-05-22  0:46       ` Vladimir Zapolskiy
2015-05-25  0:07         ` Tejun Heo

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=20150521221423.GK4914@htj.duckdns.org \
    --to=tj@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vz@mleia.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

all inboxes | Powered by JetHome®