Re: proposed patches for 2.3.11

Matthew Kirkwood (weejock@ferret.lmh.ox.ac.uk)
Wed, 21 Jul 1999 11:47:59 +0100 (GMT)


On Wed, 21 Jul 1999, Matthew Kirkwood wrote:

> Following are two patches against clean 2.3.10 which I'd like to submit
> for 2.3.near_future.

Whoops, here they are:

1. Bounding set

diff -ru linux-2.3.10-clean/include/linux/capability.h linux-2.3.10/include/linux/capability.h
--- linux-2.3.10-clean/include/linux/capability.h Wed Jul 7 17:20:40 1999
+++ linux-2.3.10/include/linux/capability.h Tue Jul 20 20:55:54 1999
@@ -264,6 +264,10 @@
#define CAP_SYS_TTY_CONFIG 26

#ifdef __KERNEL__
+/*
+ * Bounding set
+ */
+extern kernel_cap_t cap_bset;

/*
* Internal kernel functions only
@@ -289,7 +293,7 @@
#define CAP_TO_MASK(x) (1 << (x))
#define cap_raise(c, flag) (cap_t(c) |= CAP_TO_MASK(flag))
#define cap_lower(c, flag) (cap_t(c) &= ~CAP_TO_MASK(flag))
-#define cap_raised(c, flag) (cap_t(c) & CAP_TO_MASK(flag))
+#define cap_raised(c, flag) (cap_t(c) & CAP_TO_MASK(flag) & cap_bset)

static inline kernel_cap_t cap_combine(kernel_cap_t a, kernel_cap_t b)
{
diff -ru linux-2.3.10-clean/include/linux/sysctl.h linux-2.3.10/include/linux/sysctl.h
--- linux-2.3.10-clean/include/linux/sysctl.h Fri Jun 25 09:05:12 1999
+++ linux-2.3.10/include/linux/sysctl.h Tue Jul 20 21:09:52 1999
@@ -78,7 +78,7 @@
KERN_NODENAME=7,
KERN_DOMAINNAME=8,

- KERN_SECURELVL=14, /* int: system security level */
+ KERN_CAP_BSET=14, /* int: system security level */
KERN_PANIC=15, /* int: panic timeout */
KERN_REALROOTDEV=16, /* real root device to mount after initrd */

@@ -507,6 +507,8 @@
void *, size_t *);
extern int proc_dointvec(ctl_table *, int, struct file *,
void *, size_t *);
+extern int proc_dointvec_bset(ctl_table *, int, struct file *,
+ void *, size_t *);
extern int proc_dointvec_minmax(ctl_table *, int, struct file *,
void *, size_t *);
extern int proc_dointvec_jiffies(ctl_table *, int, struct file *,
diff -ru linux-2.3.10-clean/kernel/capability.c linux-2.3.10/kernel/capability.c
--- linux-2.3.10-clean/kernel/capability.c Fri Nov 20 19:43:19 1998
+++ linux-2.3.10/kernel/capability.c Tue Jul 20 18:50:24 1999
@@ -17,6 +17,8 @@
* uninteresting and/or not to be changed.
*/

+kernel_cap_t cap_bset = CAP_FULL_SET;
+
asmlinkage int sys_capget(cap_user_header_t header, cap_user_data_t dataptr)
{
int error, pid;
diff -ru linux-2.3.10-clean/kernel/ksyms.c linux-2.3.10/kernel/ksyms.c
--- linux-2.3.10-clean/kernel/ksyms.c Mon Jul 5 19:45:30 1999
+++ linux-2.3.10/kernel/ksyms.c Tue Jul 20 18:50:24 1999
@@ -350,6 +350,7 @@
EXPORT_SYMBOL(secure_tcp_sequence_number);
EXPORT_SYMBOL(get_random_bytes);
EXPORT_SYMBOL(securebits);
+EXPORT_SYMBOL(cap_bset);

/* Program loader interfaces */
EXPORT_SYMBOL(setup_arg_pages);
diff -ru linux-2.3.10-clean/kernel/sysctl.c linux-2.3.10/kernel/sysctl.c
--- linux-2.3.10-clean/kernel/sysctl.c Tue Jul 6 04:35:18 1999
+++ linux-2.3.10/kernel/sysctl.c Tue Jul 20 18:50:51 1999
@@ -20,6 +20,7 @@
#include <linux/utsname.h>
#include <linux/smp_lock.h>
#include <linux/init.h>
+#include <linux/capability.h>

#include <asm/uaccess.h>

@@ -165,6 +166,8 @@
0644, NULL, &proc_doutsstring, &sysctl_string},
{KERN_PANIC, "panic", &panic_timeout, sizeof(int),
0644, NULL, &proc_dointvec},
+ {KERN_CAP_BSET, "cap-bound", &cap_bset, sizeof(kernel_cap_t),
+ 0600, NULL, &proc_dointvec_bset},
#ifdef CONFIG_BLK_DEV_INITRD
{KERN_REALROOTDEV, "real-root-dev", &real_root_dev, sizeof(int),
0644, NULL, &proc_dointvec},
@@ -679,8 +682,13 @@
return r;
}

+#define OP_SET 0
+#define OP_AND 1
+#define OP_OR 2
+#define OP_MAX 3
+#define OP_MIN 4
static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
- void *buffer, size_t *lenp, int conv)
+ void *buffer, size_t *lenp, int conv, int op)
{
int *i, vleft, first=1, len, left, neg, val;
#define TMPBUFLEN 20
@@ -731,7 +739,17 @@
val = -val;
buffer += len;
left -= len;
- *i = val;
+ switch(op) {
+ case OP_SET: *i = val; break;
+ case OP_AND: *i &= val; break;
+ case OP_OR: *i |= val; break;
+ case OP_MAX: if(*i < val)
+ *i = val;
+ break;
+ case OP_MIN: if(*i > val)
+ *i = val;
+ break;
+ }
} else {
p = buf;
if (!first)
@@ -773,9 +791,21 @@
int proc_dointvec(ctl_table *table, int write, struct file *filp,
void *buffer, size_t *lenp)
{
- return do_proc_dointvec(table,write,filp,buffer,lenp,1);
+ return do_proc_dointvec(table,write,filp,buffer,lenp,1,OP_SET);
}

+/*
+ * init may raise the set.
+ */
+
+int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
+ void *buffer, size_t *lenp)
+{
+ return do_proc_dointvec(table,write,filp,buffer,lenp,1,
+ (current->pid == 1) ? OP_SET : OP_AND);
+}
+
+
int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
void *buffer, size_t *lenp)
{
@@ -878,7 +908,7 @@
int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
void *buffer, size_t *lenp)
{
- return do_proc_dointvec(table,write,filp,buffer,lenp,HZ);
+ return do_proc_dointvec(table,write,filp,buffer,lenp,HZ,OP_SET);
}

#else /* CONFIG_PROC_FS */

2. Memory device paranoia

diff -ru linux-2.3.10-clean/drivers/char/mem.c linux-2.3.10/drivers/char/mem.c
--- linux-2.3.10-clean/drivers/char/mem.c Sat May 15 02:15:02 1999
+++ linux-2.3.10/drivers/char/mem.c Tue Jul 20 18:36:09 1999
@@ -16,6 +16,7 @@
#include <linux/init.h>
#include <linux/joystick.h>
#include <linux/i2c.h>
+#include <linux/capability.h>

#include <asm/uaccess.h>
#include <asm/io.h>
@@ -458,11 +459,19 @@
}
}

+static int open_port(struct inode * inode, struct file * filp)
+{
+ return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
+}
+
+
#define mmap_kmem mmap_mem
#define zero_lseek null_lseek
#define full_lseek null_lseek
#define write_zero write_null
#define read_full read_zero
+#define open_mem open_port /* different capability? */
+#define open_kmem open_mem

static struct file_operations mem_fops = {
memory_lseek,
@@ -472,7 +481,7 @@
NULL, /* mem_poll */
NULL, /* mem_ioctl */
mmap_mem,
- NULL, /* no special open code */
+ open_mem,
NULL, /* flush */
NULL, /* no special release code */
NULL /* fsync */
@@ -486,7 +495,7 @@
NULL, /* kmem_poll */
NULL, /* kmem_ioctl */
mmap_kmem,
- NULL, /* no special open code */
+ open_kmem,
NULL, /* flush */
NULL, /* no special release code */
NULL /* fsync */
@@ -514,7 +523,7 @@
NULL, /* port_poll */
NULL, /* port_ioctl */
NULL, /* port_mmap */
- NULL, /* no special open code */
+ open_port,
NULL, /* flush */
NULL, /* no special release code */
NULL /* fsync */
diff -ru linux-2.3.10-clean/fs/proc/array.c linux-2.3.10/fs/proc/array.c
--- linux-2.3.10-clean/fs/proc/array.c Sat Jul 3 20:04:12 1999
+++ linux-2.3.10/fs/proc/array.c Tue Jul 20 20:16:18 1999
@@ -76,6 +76,11 @@
#endif


+static int open_kcore(struct inode * inode, struct file * filp)
+{
+ return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
+}
+
static ssize_t read_core(struct file * file, char * buf,
size_t count, loff_t *ppos)
{
@@ -137,6 +142,12 @@
static struct file_operations proc_kcore_operations = {
NULL, /* lseek */
read_core,
+ NULL, /* write */
+ NULL, /* readdir */
+ NULL, /* poll */
+ NULL, /* ioctl */
+ NULL, /* mmap */
+ open_kcore
};

struct inode_operations proc_kcore_inode_operations = {

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/