* [PATCH] cifs: potential buffer overflow in handling symlinks
@ 2022-04-12 4:38 Harshit Mogalapalli
2022-04-12 22:32 ` Steve French
0 siblings, 1 reply; 3+ messages in thread
From: Harshit Mogalapalli @ 2022-04-12 4:38 UTC (permalink / raw)
Cc: harshit.m.mogalapalli, dan.carpenter, Steve French,
Stefan Metzmacher, linux-cifs, samba-technical, linux-kernel
Smatch printed a warning:
arch/x86/crypto/poly1305_glue.c:198 poly1305_update_arch() error:
__memcpy() 'dctx->buf' too small (16 vs u32max)
It's caused because Smatch marks 'link_len' as untrusted since it comes
from sscanf(). Add a check to ensure that 'link_len' is not larger than
the size of the 'link_str' buffer.
Fixes: c69c1b6eaea1 ("cifs: implement CIFSParseMFSymlink()")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
fs/cifs/link.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index 852e54e..ebfedae 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -85,6 +85,9 @@
if (rc != 1)
return -EINVAL;
+ if (link_len > buf_len - CIFS_MF_SYMLINK_LINK_OFFSET)
+ return -EINVAL;
+
rc = symlink_hash(link_len, link_str, md5_hash);
if (rc) {
cifs_dbg(FYI, "%s: MD5 hash failure: %d\n", __func__, rc);
--
1.8.3.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cifs: potential buffer overflow in handling symlinks
2022-04-12 4:38 [PATCH] cifs: potential buffer overflow in handling symlinks Harshit Mogalapalli
@ 2022-04-12 22:32 ` Steve French
2022-04-13 8:35 ` Harshit Mogalapalli
0 siblings, 1 reply; 3+ messages in thread
From: Steve French @ 2022-04-12 22:32 UTC (permalink / raw)
To: Harshit Mogalapalli
Cc: Dan Carpenter, Steve French, Stefan Metzmacher, samba-technical,
LKML, ronnie sahlberg
Wouldn't it be easier and clearer to do the compare vs the maximum len ie
if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN)
instead of
if (link_len > buf_len - CIFS_MF_SYMLINK_LINK_OFFSET)
since buf_len is CIFS_MF_SYMLINK_FILE_SIZE and looking at link.c line
26 and 27 this means we can use CIFS_MF_SYMLINK_LINK_OFFSET for the
comparison:
#define CIFS_MF_SYMLINK_LINK_MAXLEN (1024)
#define CIFS_MF_SYMLINK_FILE_SIZE \
(CIFS_MF_SYMLINK_LINK_OFFSET + CIFS_MF_SYMLINK_LINK_MAXLEN)
On Tue, Apr 12, 2022 at 1:01 AM Harshit Mogalapalli
<harshit.m.mogalapalli@oracle.com> wrote:
>
> Smatch printed a warning:
> arch/x86/crypto/poly1305_glue.c:198 poly1305_update_arch() error:
> __memcpy() 'dctx->buf' too small (16 vs u32max)
>
> It's caused because Smatch marks 'link_len' as untrusted since it comes
> from sscanf(). Add a check to ensure that 'link_len' is not larger than
> the size of the 'link_str' buffer.
>
> Fixes: c69c1b6eaea1 ("cifs: implement CIFSParseMFSymlink()")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> ---
> fs/cifs/link.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/cifs/link.c b/fs/cifs/link.c
> index 852e54e..ebfedae 100644
> --- a/fs/cifs/link.c
> +++ b/fs/cifs/link.c
> @@ -85,6 +85,9 @@
> if (rc != 1)
> return -EINVAL;
>
> + if (link_len > buf_len - CIFS_MF_SYMLINK_LINK_OFFSET)
> + return -EINVAL;
> +
> rc = symlink_hash(link_len, link_str, md5_hash);
> if (rc) {
> cifs_dbg(FYI, "%s: MD5 hash failure: %d\n", __func__, rc);
> --
> 1.8.3.1
>
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cifs: potential buffer overflow in handling symlinks
2022-04-12 22:32 ` Steve French
@ 2022-04-13 8:35 ` Harshit Mogalapalli
0 siblings, 0 replies; 3+ messages in thread
From: Harshit Mogalapalli @ 2022-04-13 8:35 UTC (permalink / raw)
To: Steve French
Cc: Dan Carpenter, Steve French, Stefan Metzmacher, samba-technical,
LKML, ronnie sahlberg
Hi Steve,
On 13/04/22 4:02 am, Steve French wrote:
> Wouldn't it be easier and clearer to do the compare vs the maximum len ie
>
> if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN)
>
Yes, thats cleaner. Will send a v2 patch.
Thanks,
Harshit
> instead of
>
> if (link_len > buf_len - CIFS_MF_SYMLINK_LINK_OFFSET)
>
> since buf_len is CIFS_MF_SYMLINK_FILE_SIZE and looking at link.c line
> 26 and 27 this means we can use CIFS_MF_SYMLINK_LINK_OFFSET for the
> comparison:
>
> #define CIFS_MF_SYMLINK_LINK_MAXLEN (1024)
> #define CIFS_MF_SYMLINK_FILE_SIZE \
> (CIFS_MF_SYMLINK_LINK_OFFSET + CIFS_MF_SYMLINK_LINK_MAXLEN)
>
> On Tue, Apr 12, 2022 at 1:01 AM Harshit Mogalapalli
> <harshit.m.mogalapalli@oracle.com> wrote:
>>
>> Smatch printed a warning:
>> arch/x86/crypto/poly1305_glue.c:198 poly1305_update_arch() error:
>> __memcpy() 'dctx->buf' too small (16 vs u32max)
>>
>> It's caused because Smatch marks 'link_len' as untrusted since it comes
>> from sscanf(). Add a check to ensure that 'link_len' is not larger than
>> the size of the 'link_str' buffer.
>>
>> Fixes: c69c1b6eaea1 ("cifs: implement CIFSParseMFSymlink()")
>> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
>> ---
>> fs/cifs/link.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/fs/cifs/link.c b/fs/cifs/link.c
>> index 852e54e..ebfedae 100644
>> --- a/fs/cifs/link.c
>> +++ b/fs/cifs/link.c
>> @@ -85,6 +85,9 @@
>> if (rc != 1)
>> return -EINVAL;
>>
>> + if (link_len > buf_len - CIFS_MF_SYMLINK_LINK_OFFSET)
>> + return -EINVAL;
>> +
>> rc = symlink_hash(link_len, link_str, md5_hash);
>> if (rc) {
>> cifs_dbg(FYI, "%s: MD5 hash failure: %d\n", __func__, rc);
>> --
>> 1.8.3.1
>>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-13 8:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 4:38 [PATCH] cifs: potential buffer overflow in handling symlinks Harshit Mogalapalli
2022-04-12 22:32 ` Steve French
2022-04-13 8:35 ` Harshit Mogalapalli
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®