Skip to contentSkip to conversation

cgroups: strcpy destination string overflow

PATCH In review Evgeny Kuznetsov 6 participants 7 messages Oct 5, 2010 3 messages not in the archive

lore
Share & tools
lore
#0 lore raw

cover cgroups: strcpy destination string overflow

Hi,

Here is patch which fixes minor bug in /kernel/cgroup.c file. Function "strcpy" is used without check for maximum allowed source string length and could cause destination string overflow.

Thanks,
Best Regards,
Evgeny

Evgeny Kuznetsov (1):
cgroups: strcpy destination string overflow

 kernel/cgroup.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

A message that is not in the archive (sent off-list or not yet received): cover.1286193571.git.EXT-Eugeny.Kuznetsov-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 1/1 cgroups: strcpy destination string overflow

From: Evgeny Kuznetsov <[email protected]>

Function "strcpy" is used without check for maximum allowed source string length and could cause destination string overflow. Check for string length is added before using "strcpy". Function now is return error if source string length is more than a maximum.

---
 kernel/cgroup.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
kernel/cgroup.c +2 -0
index c9483d8..82bbede 100644
@@ -1883,6 +1883,8 @@ static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft,
 				      const char *buffer)
 {
 	BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
+	if (strlen(buffer) >= PATH_MAX)
+		return -EINVAL;
 	if (!cgroup_lock_live_group(cgrp))
 		return -ENODEV;
 	strcpy(cgrp->root->release_agent_path, buffer);
Signature · 1 line
1.6.3.3
#3 lore raw

PATCH 1/1 cgroups: strcpy destination string overflow

In reply to Evgeny Kuznetsov

From: Evgeny Kuznetsov <[email protected]>

Function "strcpy" is used without check for maximum allowed source string length and could cause destination string overflow. Check for string length is added before using "strcpy". Function now is return error if source string length is more than a maximum.

---
 kernel/cgroup.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
kernel/cgroup.c +2 -0
index c9483d8..82bbede 100644
@@ -1883,6 +1883,8 @@ static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft,
 				      const char *buffer)
 {
 	BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
+	if (strlen(buffer) >= PATH_MAX)
+		return -EINVAL;
 	if (!cgroup_lock_live_group(cgrp))
 		return -ENODEV;
 	strcpy(cgrp->root->release_agent_path, buffer);
Signature · 1 line
1.6.3.3

A message that is not in the archive (sent off-list or not yet received): 2acb25707f916de866aa520b1a9f04f0f48c949c.1286193571.git.EXT-Eugeny.Kuznetsov-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org

#5 lore raw
Quoted 18 lines · On Tue, 5 Oct 2010 12:38:05 +0400 Evgeny Kuznetsov…

From: Evgeny Kuznetsov <[email protected]>

Function "strcpy" is used without check for maximum allowed source string length and could cause destination string overflow. Check for string length is added before using "strcpy". Function now is return error if source string length is more than a maximum.

---
 kernel/cgroup.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
kernel/cgroup.c +0 -0
index c9483d8..82bbede 100644

kernel/cgroup.c static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft, · line 1890

Quoted 8 lines
kernel/cgroup.c +2 -0
@@ -1883,6 +1883,8 @@ static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft,
 				      const char *buffer)
 {
 	BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
+	if (strlen(buffer) >= PATH_MAX)
+		return -EINVAL;
 	if (!cgroup_lock_live_group(cgrp))
 		return -ENODEV;
 	strcpy(cgrp->root->release_agent_path, buffer);

I don't think this can happen, because cftype.max_write_len is PATH_MAX.

But it's pretty unobvious if this is actually true, and the code is fragile against future changes.

#6 lore raw
In reply to Evgeny Kuznetsov
Quoted 18 lines · On Tue, 5 Oct 2010 12:38:05 +0400 Evgeny Kuznetsov…

From: Evgeny Kuznetsov <[email protected]>

Function "strcpy" is used without check for maximum allowed source string length and could cause destination string overflow. Check for string length is added before using "strcpy". Function now is return error if source string length is more than a maximum.

---
 kernel/cgroup.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
kernel/cgroup.c +0 -0
index c9483d8..82bbede 100644

kernel/cgroup.c static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft, · line 1890

Quoted 8 lines
kernel/cgroup.c +2 -0
@@ -1883,6 +1883,8 @@ static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft,
 				      const char *buffer)
 {
 	BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
+	if (strlen(buffer) >= PATH_MAX)
+		return -EINVAL;
 	if (!cgroup_lock_live_group(cgrp))
 		return -ENODEV;
 	strcpy(cgrp->root->release_agent_path, buffer);

I don't think this can happen, because cftype.max_write_len is PATH_MAX.

But it's pretty unobvious if this is actually true, and the code is fragile against future changes.

A message that is not in the archive (sent off-list or not yet received): 20101005124802.989f6214.akpm-de/[email protected]

Acked-by
#8 lore raw
Quoted 16 lines · Andrew Morton
Quoted 13 lines · On Tue,  5 Oct 2010 12:38:05 +0400 Evgeny Kuznetsov…

From: Evgeny Kuznetsov <[email protected]>

Function "strcpy" is used without check for maximum allowed source string length and could cause destination string overflow. Check for string length is added before using "strcpy". Function now is return error if source string length is more than a maximum.

---
 kernel/cgroup.c |    2 ++

 1 files changed, 2 insertions(+), 0 deletions(-)
Quoted 16 lines

kernel/cgroup.c static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft, · line 1890

Quoted 13 lines
kernel/cgroup.c +2 -0
index c9483d8..82bbede 100644
@@ -1883,6 +1883,8 @@ static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft,
                                     const char *buffer)
  {
       BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
+     if (strlen(buffer) >= PATH_MAX)
+             return -EINVAL;
       if (!cgroup_lock_live_group(cgrp))
               return -ENODEV;
       strcpy(cgrp->root->release_agent_path, buffer);

I don't think this can happen, because cftype.max_write_len is PATH_MAX.

Yes, it shouldn't be possible.

Quoted 3 lines

But it's pretty unobvious if this is actually true, and the code is fragile against future changes.

Fair enough - adding the check doesn't hurt anything.

Acked-by
#9 lore raw
In reply to Andrew Morton
Quoted 16 lines · Andrew Morton
Quoted 13 lines · On Tue,  5 Oct 2010 12:38:05 +0400 Evgeny Kuznetsov…

From: Evgeny Kuznetsov <[email protected]>

Function "strcpy" is used without check for maximum allowed source string length and could cause destination string overflow. Check for string length is added before using "strcpy". Function now is return error if source string length is more than a maximum.

---
 kernel/cgroup.c |    2 ++

 1 files changed, 2 insertions(+), 0 deletions(-)
Quoted 16 lines

kernel/cgroup.c static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft, · line 1890

Quoted 13 lines
kernel/cgroup.c +2 -0
index c9483d8..82bbede 100644
@@ -1883,6 +1883,8 @@ static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft,
                                     const char *buffer)
  {
       BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
+     if (strlen(buffer) >= PATH_MAX)
+             return -EINVAL;
       if (!cgroup_lock_live_group(cgrp))
               return -ENODEV;
       strcpy(cgrp->root->release_agent_path, buffer);

I don't think this can happen, because cftype.max_write_len is PATH_MAX.

Yes, it shouldn't be possible.

Quoted 3 lines

But it's pretty unobvious if this is actually true, and the code is fragile against future changes.

Fair enough - adding the check doesn't hurt anything.