From: Arnd Bergmann <arnd@arndb.de>
To: unlisted-recipients:; (no To-header on input)
Cc: Kees Cook <keescook@chromium.org>,
Andrew Morton <akpm@linux-foundation.org>,
Arnd Bergmann <arnd@arndb.de>,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] adfs: use 'unsigned' types for memcpy length
Date: Tue, 1 Aug 2017 14:04:04 +0200 [thread overview]
Message-ID: <20170801120438.1582336-2-arnd@arndb.de> (raw)
In-Reply-To: <20170801120438.1582336-1-arnd@arndb.de>
After commit 62d1034f53e3 ("fortify: use WARN instead of BUG for now"), we
get a warning in adfs about a possible buffer overflow:
In function 'memcpy',
inlined from '__adfs_dir_put' at fs/adfs/dir_f.c:318:2,
inlined from 'adfs_f_update' at fs/adfs/dir_f.c:403:2:
include/linux/string.h:305:4: error: call to '__read_overflow2' declared with attribute error: detected read beyond size of object passed as 2nd parameter
__read_overflow2();
^~~~~~~~~~~~~~~~~~
The warning is correct in the sense that a negative 'pos' argument
to the function would have that result. However, this is not a bug,
as we know the position is always positive (in fact, between 5
and 2007, inclusive) when the function gets called.
Changing the variable to a unsigned type avoids the problem. I decided
to use 'unsigned int' for the position in the directory and the block
number, as they are both counting things, but use size_t for the
offset and length that get passed into memcpy. This shuts up the
warning.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
fs/adfs/dir_f.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/adfs/dir_f.c b/fs/adfs/dir_f.c
index 0fbfd0b04ae0..dab3595a1ecc 100644
--- a/fs/adfs/dir_f.c
+++ b/fs/adfs/dir_f.c
@@ -283,11 +283,12 @@ __adfs_dir_get(struct adfs_dir *dir, int pos, struct object_info *obj)
}
static int
-__adfs_dir_put(struct adfs_dir *dir, int pos, struct object_info *obj)
+__adfs_dir_put(struct adfs_dir *dir, unsigned int pos, struct object_info *obj)
{
struct super_block *sb = dir->sb;
struct adfs_direntry de;
- int thissize, buffer, offset;
+ unsigned int buffer;
+ size_t thissize, offset;
buffer = pos >> sb->s_blocksize_bits;
--
2.9.0
next prev parent reply other threads:[~2017-08-01 12:05 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-26 18:52 [PATCH v2] fortify: Use WARN instead of BUG for now Kees Cook
2017-07-26 19:55 ` Josh Poimboeuf
2017-07-26 21:33 ` Kees Cook
2017-07-29 8:56 ` kbuild test robot
2017-08-01 12:04 ` [PATCH 1/2] ext4: fix warning about stack corruption Arnd Bergmann
2017-08-01 12:04 ` Arnd Bergmann [this message]
2017-08-01 18:20 ` [PATCH 2/2] adfs: use 'unsigned' types for memcpy length Kees Cook
2017-08-01 21:43 ` Stephen Rothwell
2017-08-01 18:26 ` [PATCH 1/2] ext4: fix warning about stack corruption Kees Cook
2017-08-06 1:53 ` Theodore Ts'o
2017-08-06 20:34 ` Arnd Bergmann
2017-08-07 6:42 ` Chandan Rajendra
2017-08-22 11:08 ` Anton Blanchard
2017-08-22 11:57 ` Arnd Bergmann
2017-08-22 12:23 ` Anton Blanchard
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=20170801120438.1582336-2-arnd@arndb.de \
--to=arnd@arndb.de \
--cc=akpm@linux-foundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
/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®