Re: [PATCH v5 1/4] btrfs: extent_io: do extra check for extent buffer read write functions

David Sterba
2020-08-20T15:19:22Z

On Thu, Aug 20, 2020 at 04:46:47PM +0200, David Sterba wrote:
> On Thu, Aug 20, 2020 at 05:58:53PM +0800, Qu Wenruo wrote:
> check_add_overflow(start, len) || start + len > eb->len

--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -13,6 +13,7 @@
#include <linux/pagevec.h>
#include <linux/prefetch.h>
#include <linux/cleancache.h>
+#include <linux/overflow.h>
#include "extent_io.h"
#include "extent-io-tree.h"
#include "extent_map.h"
@@ -5641,9 +5642,10 @@ static void report_eb_range(const struct extent_buffer *eb, unsigned long start,
static inline int check_eb_range(const struct extent_buffer *eb,
unsigned long start, unsigned long len)
{
+ unsigned long offset;
+
/* start, start + len should not go beyond eb->len nor overflow */
- if (unlikely(start > eb->len || start + len > eb->len ||
- len > eb->len)) {
+ if (unlikely(check_add_overflow(start, len, &offset) || offset > eb->len)) {
report_eb_range(eb, start, len);
return -EINVAL;
}
---