mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@redhat.com>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: npiggin@suse.de
Subject: Re: [PATCH] iov_iter: have iov_iter_advance decrement nr_segs appropriately
Date: Mon, 15 Aug 2011 14:10:19 -0400	[thread overview]
Message-ID: <20110815141019.76e4abfb@tlielax.poochiereds.net> (raw)
In-Reply-To: <1313431646-14961-1-git-send-email-jlayton@redhat.com>

On Mon, 15 Aug 2011 14:07:26 -0400
Jeff Layton <jlayton@redhat.com> wrote:

> Currently, when you call iov_iter_advance, then the pointer to the kvec
> array can be incremented, but it does not decrement the nr_segs value in
> the iov_iter struct. The result is a iov_iter struct with a nr_segs
> value that goes beyond the end of the array.
> 
> While I'm not aware of anything that's specifically broken by this, it
> seems odd and a bit dangerous not to decrement that value. If someone
> were to trust the nr_segs value to be correct, then they could end up
> walking off the end of the array.
> 
> Changing this might also provide some micro-optimization when dealing
> with the last kvec in an array. Many of the other routines that deal
> with iov_iter have optimized codepaths when nr_segs == 1.
> 
> Cc: Nick Piggin <npiggin@suse.de>
> Signed-off-by: Jeff Layton <jlayton@redhat.com>
> ---
>  mm/filemap.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 


...and of course, I got the description wrong:

    s/kvec/iovec/

...I believe the patch itself is fine though.

> diff --git a/mm/filemap.c b/mm/filemap.c
> index 645a080..86508cc 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2113,6 +2113,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
>  	} else {
>  		const struct iovec *iov = i->iov;
>  		size_t base = i->iov_offset;
> +		unsigned long nr_segs = i->nr_segs;
>  
>  		/*
>  		 * The !iov->iov_len check ensures we skip over unlikely
> @@ -2128,11 +2129,13 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
>  			base += copy;
>  			if (iov->iov_len == base) {
>  				iov++;
> +				nr_segs--;
>  				base = 0;
>  			}
>  		}
>  		i->iov = iov;
>  		i->iov_offset = base;
> +		i->nr_segs = nr_segs;
>  	}
>  }
>  EXPORT_SYMBOL(iov_iter_advance);


-- 
Jeff Layton <jlayton@redhat.com>

      reply	other threads:[~2011-08-15 18:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-15 18:07 Jeff Layton
2011-08-15 18:10 ` Jeff Layton [this message]

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=20110815141019.76e4abfb@tlielax.poochiereds.net \
    --to=jlayton@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=npiggin@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

all inboxes | Powered by JetHome®