2001-04-18 20:29:06

by Erik Mouw

[permalink] [raw]
Subject: [PATCH] proc_mknod() should check the mode parameter

Hi all,

While documenting the procfs interface (more of that later), I came
across proc_mknod() which is supposed to be used to create devices in
the procfs. IMHO it should therefore check if the mode parameter
contains S_IFBLK or S_IFCHR. Here is a patch (against linux-2.4.4-pre3)
to do that:

Index: fs/proc/generic.c
===================================================================
RCS file: /home/erik/cvsroot/elinux/fs/proc/generic.c,v
retrieving revision 1.1.1.16
diff -u -r1.1.1.16 generic.c
--- fs/proc/generic.c 2001/04/08 23:34:42 1.1.1.16
+++ fs/proc/generic.c 2001/04/18 20:20:39
@@ -445,6 +445,9 @@
const char *fn = name;
int len;

+ if (! (S_ISCHR(mode) || S_ISBLK(mode)))
+ goto out;
+
if (!parent && xlate_proc_name(name, &parent, &fn) != 0)
goto out;
len = strlen(fn);



Erik

--
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands
Phone: +31-15-2783635 Fax: +31-15-2781843 Email: [email protected]
WWW: http://www-ict.its.tudelft.nl/~erik/


2001-04-18 21:51:39

by Alexander Viro

[permalink] [raw]
Subject: Re: [PATCH] proc_mknod() should check the mode parameter



On Wed, 18 Apr 2001, Erik Mouw wrote:

> Hi all,
>
> While documenting the procfs interface (more of that later), I came
> across proc_mknod() which is supposed to be used to create devices in
> the procfs. IMHO it should therefore check if the mode parameter
> contains S_IFBLK or S_IFCHR.

Why? All callers of proc_mknod() are in the kernel and they should
know better. I could understand
if (....)
BUG();
but silently doing nothing is really odd.

2001-04-18 21:57:29

by Erik Mouw

[permalink] [raw]
Subject: Re: [PATCH] proc_mknod() should check the mode parameter

On Wed, Apr 18, 2001 at 05:51:08PM -0400, Alexander Viro wrote:
> On Wed, 18 Apr 2001, Erik Mouw wrote:
> > While documenting the procfs interface (more of that later), I came
> > across proc_mknod() which is supposed to be used to create devices in
> > the procfs. IMHO it should therefore check if the mode parameter
> > contains S_IFBLK or S_IFCHR.
>
> Why? All callers of proc_mknod() are in the kernel and they should
> know better. I could understand
> if (....)
> BUG();
> but silently doing nothing is really odd.

OK, what about this one:

Index: fs/proc/generic.c
===================================================================
RCS file: /home/erik/cvsroot/elinux/fs/proc/generic.c,v
retrieving revision 1.1.1.16
diff -u -r1.1.1.16 generic.c
--- fs/proc/generic.c 2001/04/08 23:34:42 1.1.1.16
+++ fs/proc/generic.c 2001/04/18 21:55:14
@@ -445,6 +445,9 @@
const char *fn = name;
int len;

+ if (! (S_ISCHR(mode) || S_ISBLK(mode)))
+ BUG();
+
if (!parent && xlate_proc_name(name, &parent, &fn) != 0)
goto out;
len = strlen(fn);


Erik

--
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands
Phone: +31-15-2783635 Fax: +31-15-2781843 Email: [email protected]
WWW: http://www-ict.its.tudelft.nl/~erik/