Skip to contentSkip to conversation

mdopen: Prevent overrunning the devname buffer when copying devnm into it for long md names.

PATCH Applied Robert LeBlanc 3 participants 4 messages Aug 24, 2016 – Aug 25, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mdopen: Prevent overrunning the devname buffer when copying devnm into it for long md names.

Linux allows for 32 character device names. When using the maximum size device name and also storing "/dev/", devname needs to be 37 character long to store the complete device name. i.e. "/dev/md_abcdefghijklmnopqrstuvwxyz12\0"

Signed-Off: Robert LeBlanc<[email protected]>

---
 mdopen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mdopen.c +1 -1
index f818fdf..5af344b 100644
@@ -144,7 +144,7 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
 	struct createinfo *ci = conf_get_create_info();
 	int parts;
 	char *cname;
-	char devname[20];
+	char devname[37];
 	char devnm[32];
 	char cbuf[400];
 	if (chosen == NULL)
Signature · 1 line
2.9.3
#1 lore raw
Quoted 14 lines · Robert LeBlanc

Linux allows for 32 character device names. When using the maximum size device name and also storing "/dev/", devname needs to be 37 character long to store the complete device name. i.e. "/dev/md_abcdefghijklmnopqrstuvwxyz12\0"

Signed-Off: Robert LeBlanc<[email protected]>

---
 mdopen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mdopen.c +0 -0
index f818fdf..5af344b 100644

mdopen.c int create_mddev(char *dev, char *name, int autof, int trustworthy, · line 147

Quoted 5 lines
mdopen.c +1 -1
@@ -144,7 +144,7 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
        struct createinfo *ci = conf_get_create_info();
        int parts;
        char *cname;
-       char devname[20];
+       char devname[37];

I think you want 38 here.
5 + 32 + '\0'.

Quoted 6 lines
mdopen.c +0 -1
        char devnm[32];
        char cbuf[400];
        if (chosen == NULL)
--

2.9.3

Also a sprintf() to snprintf() cleanup might not be a bad idea ..

Signature · 1 line
Shaun Tancheff
#2 lore raw
Quoted 10 lines · Shaun Tancheff
Quoted 9 lines · Robert LeBlanc

Linux allows for 32 character device names. When using the maximum size device name and also storing "/dev/", devname needs to be 37 character long to store the complete device name. i.e. "/dev/md_abcdefghijklmnopqrstuvwxyz12\0"

Signed-Off: Robert LeBlanc<[email protected]>

---
 mdopen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

mdopen.c int create_mddev(char *dev, char *name, int autof, int trustworthy, · line 147

Quoted 10 lines
mdopen.c +1 -1
index f818fdf..5af344b 100644
@@ -144,7 +144,7 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
        struct createinfo *ci = conf_get_create_info();
        int parts;
        char *cname;
-       char devname[20];
+       char devname[37];

I think you want 38 here.
5 + 32 + '\0'.

Quoted 1 line
mdopen.c +0 -0
        char devnm[32];

Ah sorry, that 32 was including the null already
implied by devnm.

Looks fine.

Quoted 9 lines
Quoted 5 lines
mdopen.c +0 -1
        char cbuf[400];
        if (chosen == NULL)
--

2.9.3

Also a sprintf() to snprintf() cleanup might not be a bad idea .. --
Shaun Tancheff

Signature · 1 line
Shaun Tancheff
Applied
#3 lore raw
In reply to Robert LeBlanc
Quoted 8 lines · Robert LeBlanc

Linux allows for 32 character device names. When using the maximum size device name and also storing "/dev/", devname needs to be 37 character long to store the complete device name. i.e. "/dev/md_abcdefghijklmnopqrstuvwxyz12\0"

Signed-Off: Robert LeBlanc<[email protected]>

---
 mdopen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Looks good - I corrected your comment to fit into a proper editor width of 80 characters, and also fixed up the SOB since it needs to say Signed-off-by rather than signed-off.

Applied!
Jes