Prev: [PATCH 0/3] vhost: logging fixes
Next: [PATCH] scripts/get_maintainer.pl: Fix possible infinite loop
From: Gleb Natapov on 23 Feb 2010 12:40 On Tue, Feb 23, 2010 at 06:57:58PM +0200, Michael S. Tsirkin wrote: > get_user_pages_fast returns number of pages on success, negative value > on failure, but never 0. Fix vhost code to match this logic. > > Signed-off-by: Michael S. Tsirkin <mst(a)redhat.com> > --- > drivers/vhost/vhost.c | 3 ++- > 1 files changed, 2 insertions(+), 1 deletions(-) > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > index d4f8fdf..d003504 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -646,8 +646,9 @@ static int set_bit_to_user(int nr, void __user *addr) > int bit = nr + (log % PAGE_SIZE) * 8; > int r; > r = get_user_pages_fast(log, 1, 1, &page); > - if (r) > + if (r < 0) > return r; > + BUG_ON(r != 1); Can't this be easily triggered from user space? > base = kmap_atomic(page, KM_USER0); > set_bit(bit, base); > kunmap_atomic(base, KM_USER0); > -- > 1.7.0.18.g0d53a5 -- Gleb. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
From: Michael S. Tsirkin on 23 Feb 2010 12:40 On Tue, Feb 23, 2010 at 07:34:34PM +0200, Gleb Natapov wrote: > On Tue, Feb 23, 2010 at 06:57:58PM +0200, Michael S. Tsirkin wrote: > > get_user_pages_fast returns number of pages on success, negative value > > on failure, but never 0. Fix vhost code to match this logic. > > > > Signed-off-by: Michael S. Tsirkin <mst(a)redhat.com> > > --- > > drivers/vhost/vhost.c | 3 ++- > > 1 files changed, 2 insertions(+), 1 deletions(-) > > > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > > index d4f8fdf..d003504 100644 > > --- a/drivers/vhost/vhost.c > > +++ b/drivers/vhost/vhost.c > > @@ -646,8 +646,9 @@ static int set_bit_to_user(int nr, void __user *addr) > > int bit = nr + (log % PAGE_SIZE) * 8; > > int r; > > r = get_user_pages_fast(log, 1, 1, &page); > > - if (r) > > + if (r < 0) > > return r; > > + BUG_ON(r != 1); > Can't this be easily triggered from user space? I think no. get_user_pages_fast always returns number of pages pinned (in this case always 1) or an error (< 0). Anything else is a kernel bug. > > base = kmap_atomic(page, KM_USER0); > > set_bit(bit, base); > > kunmap_atomic(base, KM_USER0); > > -- > > 1.7.0.18.g0d53a5 > > -- > Gleb. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
From: Michael S. Tsirkin on 23 Feb 2010 12:50 On Tue, Feb 23, 2010 at 07:39:52PM +0200, Gleb Natapov wrote: > On Tue, Feb 23, 2010 at 07:32:58PM +0200, Michael S. Tsirkin wrote: > > On Tue, Feb 23, 2010 at 07:34:34PM +0200, Gleb Natapov wrote: > > > On Tue, Feb 23, 2010 at 06:57:58PM +0200, Michael S. Tsirkin wrote: > > > > get_user_pages_fast returns number of pages on success, negative value > > > > on failure, but never 0. Fix vhost code to match this logic. > > > > > > > > Signed-off-by: Michael S. Tsirkin <mst(a)redhat.com> > > > > --- > > > > drivers/vhost/vhost.c | 3 ++- > > > > 1 files changed, 2 insertions(+), 1 deletions(-) > > > > > > > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > > > > index d4f8fdf..d003504 100644 > > > > --- a/drivers/vhost/vhost.c > > > > +++ b/drivers/vhost/vhost.c > > > > @@ -646,8 +646,9 @@ static int set_bit_to_user(int nr, void __user *addr) > > > > int bit = nr + (log % PAGE_SIZE) * 8; > > > > int r; > > > > r = get_user_pages_fast(log, 1, 1, &page); > > > > - if (r) > > > > + if (r < 0) > > > > return r; > > > > + BUG_ON(r != 1); > > > Can't this be easily triggered from user space? > > > > I think no. get_user_pages_fast always returns number of pages > > pinned (in this case always 1) or an error (< 0). > > Anything else is a kernel bug. > > > But what if page is unmapped from userspace? Then we get -EFAULT > > > > base = kmap_atomic(page, KM_USER0); > > > > set_bit(bit, base); > > > > kunmap_atomic(base, KM_USER0); > > > > -- > > > > 1.7.0.18.g0d53a5 > > > > > > -- > > > Gleb. > > -- > Gleb. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
From: Gleb Natapov on 23 Feb 2010 12:50 On Tue, Feb 23, 2010 at 07:39:08PM +0200, Michael S. Tsirkin wrote: > On Tue, Feb 23, 2010 at 07:39:52PM +0200, Gleb Natapov wrote: > > On Tue, Feb 23, 2010 at 07:32:58PM +0200, Michael S. Tsirkin wrote: > > > On Tue, Feb 23, 2010 at 07:34:34PM +0200, Gleb Natapov wrote: > > > > On Tue, Feb 23, 2010 at 06:57:58PM +0200, Michael S. Tsirkin wrote: > > > > > get_user_pages_fast returns number of pages on success, negative value > > > > > on failure, but never 0. Fix vhost code to match this logic. > > > > > > > > > > Signed-off-by: Michael S. Tsirkin <mst(a)redhat.com> > > > > > --- > > > > > drivers/vhost/vhost.c | 3 ++- > > > > > 1 files changed, 2 insertions(+), 1 deletions(-) > > > > > > > > > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > > > > > index d4f8fdf..d003504 100644 > > > > > --- a/drivers/vhost/vhost.c > > > > > +++ b/drivers/vhost/vhost.c > > > > > @@ -646,8 +646,9 @@ static int set_bit_to_user(int nr, void __user *addr) > > > > > int bit = nr + (log % PAGE_SIZE) * 8; > > > > > int r; > > > > > r = get_user_pages_fast(log, 1, 1, &page); > > > > > - if (r) > > > > > + if (r < 0) > > > > > return r; > > > > > + BUG_ON(r != 1); > > > > Can't this be easily triggered from user space? > > > > > > I think no. get_user_pages_fast always returns number of pages > > > pinned (in this case always 1) or an error (< 0). > > > Anything else is a kernel bug. > > > > > But what if page is unmapped from userspace? > > Then we get -EFAULT > Ah correct. > > > > > base = kmap_atomic(page, KM_USER0); > > > > > set_bit(bit, base); > > > > > kunmap_atomic(base, KM_USER0); > > > > > -- > > > > > 1.7.0.18.g0d53a5 > > > > > > > > -- > > > > Gleb. > > > > -- > > Gleb. -- Gleb. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
From: Gleb Natapov on 23 Feb 2010 12:50 On Tue, Feb 23, 2010 at 07:32:58PM +0200, Michael S. Tsirkin wrote: > On Tue, Feb 23, 2010 at 07:34:34PM +0200, Gleb Natapov wrote: > > On Tue, Feb 23, 2010 at 06:57:58PM +0200, Michael S. Tsirkin wrote: > > > get_user_pages_fast returns number of pages on success, negative value > > > on failure, but never 0. Fix vhost code to match this logic. > > > > > > Signed-off-by: Michael S. Tsirkin <mst(a)redhat.com> > > > --- > > > drivers/vhost/vhost.c | 3 ++- > > > 1 files changed, 2 insertions(+), 1 deletions(-) > > > > > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > > > index d4f8fdf..d003504 100644 > > > --- a/drivers/vhost/vhost.c > > > +++ b/drivers/vhost/vhost.c > > > @@ -646,8 +646,9 @@ static int set_bit_to_user(int nr, void __user *addr) > > > int bit = nr + (log % PAGE_SIZE) * 8; > > > int r; > > > r = get_user_pages_fast(log, 1, 1, &page); > > > - if (r) > > > + if (r < 0) > > > return r; > > > + BUG_ON(r != 1); > > Can't this be easily triggered from user space? > > I think no. get_user_pages_fast always returns number of pages > pinned (in this case always 1) or an error (< 0). > Anything else is a kernel bug. > But what if page is unmapped from userspace? > > > base = kmap_atomic(page, KM_USER0); > > > set_bit(bit, base); > > > kunmap_atomic(base, KM_USER0); > > > -- > > > 1.7.0.18.g0d53a5 > > > > -- > > Gleb. -- Gleb. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
|
Next
|
Last
Pages: 1 2 3 Prev: [PATCH 0/3] vhost: logging fixes Next: [PATCH] scripts/get_maintainer.pl: Fix possible infinite loop |