Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs: don't stop searching after encountering the wrong item
@ 2013-05-06 17:40 Gabriel de Perthuis
  2013-05-06 18:38 ` Greg KH
  2013-05-06 21:39 ` Gabriel de Perthuis
  0 siblings, 2 replies; 3+ messages in thread
From: Gabriel de Perthuis @ 2013-05-06 17:40 UTC (permalink / raw)
  To: linux-btrfs, Josef Bacik; +Cc: linux-stable, Tristan Seligmann

[-- Attachment #1: Type: text/plain, Size: 1318 bytes --]

The search ioctl skips items that are too large for a result buffer, but
inline items of a certain size occuring before any search result is
found would trigger an overflow and stop the search entirely.

Bug: https://bugzilla.kernel.org/show_bug.cgi?id=57641

Signed-off-by: Gabriel de Perthuis <g2p.code+btrfs@gmail.com>
---
 fs/btrfs/ioctl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 95d46cc..b3f0276 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1797,23 +1797,23 @@ static noinline int copy_to_sk(struct btrfs_root *root,
 
 	for (i = slot; i < nritems; i++) {
 		item_off = btrfs_item_ptr_offset(leaf, i);
 		item_len = btrfs_item_size_nr(leaf, i);
 
-		if (item_len > BTRFS_SEARCH_ARGS_BUFSIZE)
+		btrfs_item_key_to_cpu(leaf, key, i);
+		if (!key_in_sk(key, sk))
+			continue;
+
+		if (sizeof(sh) + item_len > BTRFS_SEARCH_ARGS_BUFSIZE)
 			item_len = 0;
 
 		if (sizeof(sh) + item_len + *sk_offset >
 		    BTRFS_SEARCH_ARGS_BUFSIZE) {
 			ret = 1;
 			goto overflow;
 		}
 
-		btrfs_item_key_to_cpu(leaf, key, i);
-		if (!key_in_sk(key, sk))
-			continue;
-
 		sh.objectid = key->objectid;
 		sh.offset = key->offset;
 		sh.type = key->type;
 		sh.len = item_len;
 		sh.transid = found_transid;
-- 
1.8.2.1.419.ga0b97c6


[-- Attachment #2: Portion de message joint --]
[-- Type: text/plain, Size: 0 bytes --]



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: don't stop searching after encountering the wrong item
  2013-05-06 17:40 [PATCH] btrfs: don't stop searching after encountering the wrong item Gabriel de Perthuis
@ 2013-05-06 18:38 ` Greg KH
  2013-05-06 21:39 ` Gabriel de Perthuis
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2013-05-06 18:38 UTC (permalink / raw)
  To: Gabriel de Perthuis; +Cc: linux-btrfs, Josef Bacik, stable, Tristan Seligmann

On Mon, May 06, 2013 at 07:40:18PM +0200, Gabriel de Perthuis wrote:
> The search ioctl skips items that are too large for a result buffer, but
> inline items of a certain size occuring before any search result is
> found would trigger an overflow and stop the search entirely.
> 
> Bug: https://bugzilla.kernel.org/show_bug.cgi?id=57641
> 
> Signed-off-by: Gabriel de Perthuis <g2p.code+btrfs@gmail.com>
> ---
>  fs/btrfs/ioctl.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read Documentation/stable_kernel_rules.txt
for how to do this properly.

</formletter>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] btrfs: don't stop searching after encountering the wrong item
  2013-05-06 17:40 [PATCH] btrfs: don't stop searching after encountering the wrong item Gabriel de Perthuis
  2013-05-06 18:38 ` Greg KH
@ 2013-05-06 21:39 ` Gabriel de Perthuis
  1 sibling, 0 replies; 3+ messages in thread
From: Gabriel de Perthuis @ 2013-05-06 21:39 UTC (permalink / raw)
  To: linux-btrfs, Josef Bacik

The search ioctl skips items that are too large for a result buffer, but
inline items of a certain size occuring before any search result is
found would trigger an overflow and stop the search entirely.

Cc: stable@vger.kernel.org
Bug: https://bugzilla.kernel.org/show_bug.cgi?id=57641

Signed-off-by: Gabriel de Perthuis <g2p.code+btrfs@gmail.com>
---
(resent, with the correct header to have stable copied)

 fs/btrfs/ioctl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 2c02310..f49b62f 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1794,23 +1794,23 @@ static noinline int copy_to_sk(struct btrfs_root *root,
 
 	for (i = slot; i < nritems; i++) {
 		item_off = btrfs_item_ptr_offset(leaf, i);
 		item_len = btrfs_item_size_nr(leaf, i);
 
-		if (item_len > BTRFS_SEARCH_ARGS_BUFSIZE)
+		btrfs_item_key_to_cpu(leaf, key, i);
+		if (!key_in_sk(key, sk))
+			continue;
+
+		if (sizeof(sh) + item_len > BTRFS_SEARCH_ARGS_BUFSIZE)
 			item_len = 0;
 
 		if (sizeof(sh) + item_len + *sk_offset >
 		    BTRFS_SEARCH_ARGS_BUFSIZE) {
 			ret = 1;
 			goto overflow;
 		}
 
-		btrfs_item_key_to_cpu(leaf, key, i);
-		if (!key_in_sk(key, sk))
-			continue;
-
 		sh.objectid = key->objectid;
 		sh.offset = key->offset;
 		sh.type = key->type;
 		sh.len = item_len;
 		sh.transid = found_transid;
-- 
1.8.2.1.419.ga0b97c6


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-05-06 21:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-06 17:40 [PATCH] btrfs: don't stop searching after encountering the wrong item Gabriel de Perthuis
2013-05-06 18:38 ` Greg KH
2013-05-06 21:39 ` Gabriel de Perthuis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox