Skip to contentSkip to conversation

cifs: fix potential overflow in cifs_compose_mount_options

PATCH Applied Insu Yun 2 participants 3 messages Feb 1, 2016 – Feb 11, 2016

Subsystems (2)
lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 cifs: fix potential overflow in cifs_compose_mount_options

In worst case, "ip=" + sb_mountdata + ipv6 can be copied into mountdata. Therefore, for safe, it is better to add more size when allocating memory.

---
 fs/cifs/cifs_dfs_ref.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/cifs_dfs_ref.c +1 -1
index 7dc886c..e956cba 100644
@@ -175,7 +175,7 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
 	 * string to the length of the original string to allow for worst case.
 	 */
 	md_len = strlen(sb_mountdata) + INET6_ADDRSTRLEN;
-	mountdata = kzalloc(md_len + 1, GFP_KERNEL);
+	mountdata = kzalloc(md_len + sizeof("ip=") + 1, GFP_KERNEL);
 	if (mountdata == NULL) {
 		rc = -ENOMEM;
 		goto compose_mount_options_err;
Signature · 1 line
1.9.1
Applied
#1 lore raw
Quoted 18 lines · Insu Yun

In worst case, "ip=" + sb_mountdata + ipv6 can be copied into mountdata. Therefore, for safe, it is better to add more size when allocating memory.

---
 fs/cifs/cifs_dfs_ref.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/cifs_dfs_ref.c +0 -0
index 7dc886c..e956cba 100644
@@ -175,7 +175,7 @@ char *cifs_compose_mount_options(const char
 *sb_mountdata,
         * string to the length of the original string to allow for worst

case.

         */
        md_len = strlen(sb_mountdata) + INET6_ADDRSTRLEN;

fs/cifs/cifs_dfs_ref.c char *cifs_compose_mount_options(const char *sb_mountdata, · line 181

Quoted 5 lines
fs/cifs/cifs_dfs_ref.c +1 -1
-       mountdata = kzalloc(md_len + 1, GFP_KERNEL);
+       mountdata = kzalloc(md_len + sizeof("ip=") + 1, GFP_KERNEL);
        if (mountdata == NULL) {
                rc = -ENOMEM;
                goto compose_mount_options_err;

Not likely to be reproducible in practice (since ip= is already in the sb_mountdata) but in case mount.cifs was missing and ip= was missing from the original mount string, might as well add it.

Merged into cifs-2.6.git

Signature · 3 lines
Thanks,

Steve
Applied
#2 lore raw
In reply to Insu Yun
Quoted 13 lines · Insu Yun

In worst case, "ip=" + sb_mountdata + ipv6 can be copied into mountdata. Therefore, for safe, it is better to add more size when allocating memory.

---
 fs/cifs/cifs_dfs_ref.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/cifs_dfs_ref.c +0 -0
index 7dc886c..e956cba 100644

fs/cifs/cifs_dfs_ref.c char *cifs_compose_mount_options(const char *sb_mountdata, · line 181

Quoted 8 lines
fs/cifs/cifs_dfs_ref.c +1 -1
@@ -175,7 +175,7 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
         * string to the length of the original string to allow for worst case.
         */
        md_len = strlen(sb_mountdata) + INET6_ADDRSTRLEN;
-       mountdata = kzalloc(md_len + 1, GFP_KERNEL);
+       mountdata = kzalloc(md_len + sizeof("ip=") + 1, GFP_KERNEL);
        if (mountdata == NULL) {
                rc = -ENOMEM;
                goto compose_mount_options_err;

Not likely to be reproducible in practice (since ip= is already in the sb_mountdata) but in case mount.cifs was missing and ip= was missing from the original mount string, might as well add it.

Merged into cifs-2.6.git

Signature · 3 lines
Thanks,

Steve