Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 832d30ca authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge branch 'for-linus' of...

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6: (38 commits)
  SELinux: Make selinux_kernel_create_files_as() shouldn't just always return 0
  TOMOYO: Protect find_task_by_vpid() with RCU.
  Security: add static to security_ops and default_security_ops variable
  selinux: libsepol: remove dead code in check_avtab_hierarchy_callback()
  TOMOYO: Remove __func__ from tomoyo_is_correct_path/domain
  security: fix a couple of sparse warnings
  TOMOYO: Remove unneeded parameter.
  TOMOYO: Use shorter names.
  TOMOYO: Use enum for index numbers.
  TOMOYO: Add garbage collector.
  TOMOYO: Add refcounter on domain structure.
  TOMOYO: Merge headers.
  TOMOYO: Add refcounter on string data.
  TOMOYO: Reduce lines by using common path for addition and deletion.
  selinux: fix memory leak in sel_make_bools
  TOMOYO: Extract bitfield
  syslog: clean up needless comment
  syslog: use defined constants instead of raw numbers
  syslog: distinguish between /proc/kmsg and syscalls
  selinux: allow MLS->non-MLS and vice versa upon policy reload
  ...
parents 3a5b27bf b4ccebdd
Loading
Loading
Loading
Loading
+7 −7
Original line number Original line Diff line number Diff line
@@ -12,37 +12,37 @@
#include <linux/poll.h>
#include <linux/poll.h>
#include <linux/proc_fs.h>
#include <linux/proc_fs.h>
#include <linux/fs.h>
#include <linux/fs.h>
#include <linux/syslog.h>


#include <asm/uaccess.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/io.h>


extern wait_queue_head_t log_wait;
extern wait_queue_head_t log_wait;


extern int do_syslog(int type, char __user *bug, int count);

static int kmsg_open(struct inode * inode, struct file * file)
static int kmsg_open(struct inode * inode, struct file * file)
{
{
	return do_syslog(1,NULL,0);
	return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_FILE);
}
}


static int kmsg_release(struct inode * inode, struct file * file)
static int kmsg_release(struct inode * inode, struct file * file)
{
{
	(void) do_syslog(0,NULL,0);
	(void) do_syslog(SYSLOG_ACTION_CLOSE, NULL, 0, SYSLOG_FROM_FILE);
	return 0;
	return 0;
}
}


static ssize_t kmsg_read(struct file *file, char __user *buf,
static ssize_t kmsg_read(struct file *file, char __user *buf,
			 size_t count, loff_t *ppos)
			 size_t count, loff_t *ppos)
{
{
	if ((file->f_flags & O_NONBLOCK) && !do_syslog(9, NULL, 0))
	if ((file->f_flags & O_NONBLOCK) &&
	    !do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_FILE))
		return -EAGAIN;
		return -EAGAIN;
	return do_syslog(2, buf, count);
	return do_syslog(SYSLOG_ACTION_READ, buf, count, SYSLOG_FROM_FILE);
}
}


static unsigned int kmsg_poll(struct file *file, poll_table *wait)
static unsigned int kmsg_poll(struct file *file, poll_table *wait)
{
{
	poll_wait(file, &log_wait, wait);
	poll_wait(file, &log_wait, wait);
	if (do_syslog(9, NULL, 0))
	if (do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_FILE))
		return POLLIN | POLLRDNORM;
		return POLLIN | POLLRDNORM;
	return 0;
	return 0;
}
}
+9 −5
Original line number Original line Diff line number Diff line
@@ -76,7 +76,7 @@ extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
extern int cap_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp);
extern int cap_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp);
extern int cap_task_setioprio(struct task_struct *p, int ioprio);
extern int cap_task_setioprio(struct task_struct *p, int ioprio);
extern int cap_task_setnice(struct task_struct *p, int nice);
extern int cap_task_setnice(struct task_struct *p, int nice);
extern int cap_syslog(int type);
extern int cap_syslog(int type, bool from_file);
extern int cap_vm_enough_memory(struct mm_struct *mm, long pages);
extern int cap_vm_enough_memory(struct mm_struct *mm, long pages);


struct msghdr;
struct msghdr;
@@ -95,6 +95,8 @@ struct seq_file;
extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
extern int cap_netlink_recv(struct sk_buff *skb, int cap);
extern int cap_netlink_recv(struct sk_buff *skb, int cap);


void reset_security_ops(void);

#ifdef CONFIG_MMU
#ifdef CONFIG_MMU
extern unsigned long mmap_min_addr;
extern unsigned long mmap_min_addr;
extern unsigned long dac_mmap_min_addr;
extern unsigned long dac_mmap_min_addr;
@@ -985,6 +987,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
 *	Check permissions on incoming network packets.  This hook is distinct
 *	Check permissions on incoming network packets.  This hook is distinct
 *	from Netfilter's IP input hooks since it is the first time that the
 *	from Netfilter's IP input hooks since it is the first time that the
 *	incoming sk_buff @skb has been associated with a particular socket, @sk.
 *	incoming sk_buff @skb has been associated with a particular socket, @sk.
 *	Must not sleep inside this hook because some callers hold spinlocks.
 *	@sk contains the sock (not socket) associated with the incoming sk_buff.
 *	@sk contains the sock (not socket) associated with the incoming sk_buff.
 *	@skb contains the incoming network data.
 *	@skb contains the incoming network data.
 * @socket_getpeersec_stream:
 * @socket_getpeersec_stream:
@@ -1348,6 +1351,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
 *	logging to the console.
 *	logging to the console.
 *	See the syslog(2) manual page for an explanation of the @type values.
 *	See the syslog(2) manual page for an explanation of the @type values.
 *	@type contains the type of action.
 *	@type contains the type of action.
 *	@from_file indicates the context of action (if it came from /proc).
 *	Return 0 if permission is granted.
 *	Return 0 if permission is granted.
 * @settime:
 * @settime:
 *	Check permission to change the system time.
 *	Check permission to change the system time.
@@ -1462,7 +1466,7 @@ struct security_operations {
	int (*sysctl) (struct ctl_table *table, int op);
	int (*sysctl) (struct ctl_table *table, int op);
	int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
	int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
	int (*quota_on) (struct dentry *dentry);
	int (*quota_on) (struct dentry *dentry);
	int (*syslog) (int type);
	int (*syslog) (int type, bool from_file);
	int (*settime) (struct timespec *ts, struct timezone *tz);
	int (*settime) (struct timespec *ts, struct timezone *tz);
	int (*vm_enough_memory) (struct mm_struct *mm, long pages);
	int (*vm_enough_memory) (struct mm_struct *mm, long pages);


@@ -1761,7 +1765,7 @@ int security_acct(struct file *file);
int security_sysctl(struct ctl_table *table, int op);
int security_sysctl(struct ctl_table *table, int op);
int security_quotactl(int cmds, int type, int id, struct super_block *sb);
int security_quotactl(int cmds, int type, int id, struct super_block *sb);
int security_quota_on(struct dentry *dentry);
int security_quota_on(struct dentry *dentry);
int security_syslog(int type);
int security_syslog(int type, bool from_file);
int security_settime(struct timespec *ts, struct timezone *tz);
int security_settime(struct timespec *ts, struct timezone *tz);
int security_vm_enough_memory(long pages);
int security_vm_enough_memory(long pages);
int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
@@ -2007,9 +2011,9 @@ static inline int security_quota_on(struct dentry *dentry)
	return 0;
	return 0;
}
}


static inline int security_syslog(int type)
static inline int security_syslog(int type, bool from_file)
{
{
	return cap_syslog(type);
	return cap_syslog(type, from_file);
}
}


static inline int security_settime(struct timespec *ts, struct timezone *tz)
static inline int security_settime(struct timespec *ts, struct timezone *tz)

include/linux/syslog.h

0 → 100644
+52 −0
Original line number Original line Diff line number Diff line
/*  Syslog internals
 *
 *  Copyright 2010 Canonical, Ltd.
 *  Author: Kees Cook <kees.cook@canonical.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef _LINUX_SYSLOG_H
#define _LINUX_SYSLOG_H

/* Close the log.  Currently a NOP. */
#define SYSLOG_ACTION_CLOSE          0
/* Open the log. Currently a NOP. */
#define SYSLOG_ACTION_OPEN           1
/* Read from the log. */
#define SYSLOG_ACTION_READ           2
/* Read all messages remaining in the ring buffer. */
#define SYSLOG_ACTION_READ_ALL       3
/* Read and clear all messages remaining in the ring buffer */
#define SYSLOG_ACTION_READ_CLEAR     4
/* Clear ring buffer. */
#define SYSLOG_ACTION_CLEAR          5
/* Disable printk's to console */
#define SYSLOG_ACTION_CONSOLE_OFF    6
/* Enable printk's to console */
#define SYSLOG_ACTION_CONSOLE_ON     7
/* Set level of messages printed to console */
#define SYSLOG_ACTION_CONSOLE_LEVEL  8
/* Return number of unread characters in the log buffer */
#define SYSLOG_ACTION_SIZE_UNREAD    9
/* Return size of the log buffer */
#define SYSLOG_ACTION_SIZE_BUFFER   10

#define SYSLOG_FROM_CALL 0
#define SYSLOG_FROM_FILE 1

int do_syslog(int type, char __user *buf, int count, bool from_file);

#endif /* _LINUX_SYSLOG_H */
+2 −2
Original line number Original line Diff line number Diff line
@@ -135,7 +135,7 @@ static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp,
	if (pid && (pid != task_pid_vnr(current))) {
	if (pid && (pid != task_pid_vnr(current))) {
		struct task_struct *target;
		struct task_struct *target;


		read_lock(&tasklist_lock);
		rcu_read_lock();


		target = find_task_by_vpid(pid);
		target = find_task_by_vpid(pid);
		if (!target)
		if (!target)
@@ -143,7 +143,7 @@ static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp,
		else
		else
			ret = security_capget(target, pEp, pIp, pPp);
			ret = security_capget(target, pEp, pIp, pPp);


		read_unlock(&tasklist_lock);
		rcu_read_unlock();
	} else
	} else
		ret = security_capget(current, pEp, pIp, pPp);
		ret = security_capget(current, pEp, pIp, pPp);


+23 −29
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@
#include <linux/kexec.h>
#include <linux/kexec.h>
#include <linux/ratelimit.h>
#include <linux/ratelimit.h>
#include <linux/kmsg_dump.h>
#include <linux/kmsg_dump.h>
#include <linux/syslog.h>


#include <asm/uaccess.h>
#include <asm/uaccess.h>


@@ -258,38 +259,23 @@ static inline void boot_delay_msec(void)
}
}
#endif
#endif


/*
int do_syslog(int type, char __user *buf, int len, bool from_file)
 * Commands to do_syslog:
 *
 * 	0 -- Close the log.  Currently a NOP.
 * 	1 -- Open the log. Currently a NOP.
 * 	2 -- Read from the log.
 * 	3 -- Read all messages remaining in the ring buffer.
 * 	4 -- Read and clear all messages remaining in the ring buffer
 * 	5 -- Clear ring buffer.
 * 	6 -- Disable printk's to console
 * 	7 -- Enable printk's to console
 *	8 -- Set level of messages printed to console
 *	9 -- Return number of unread characters in the log buffer
 *     10 -- Return size of the log buffer
 */
int do_syslog(int type, char __user *buf, int len)
{
{
	unsigned i, j, limit, count;
	unsigned i, j, limit, count;
	int do_clear = 0;
	int do_clear = 0;
	char c;
	char c;
	int error = 0;
	int error = 0;


	error = security_syslog(type);
	error = security_syslog(type, from_file);
	if (error)
	if (error)
		return error;
		return error;


	switch (type) {
	switch (type) {
	case 0:		/* Close log */
	case SYSLOG_ACTION_CLOSE:	/* Close log */
		break;
		break;
	case 1:		/* Open log */
	case SYSLOG_ACTION_OPEN:	/* Open log */
		break;
		break;
	case 2:		/* Read from log */
	case SYSLOG_ACTION_READ:	/* Read from log */
		error = -EINVAL;
		error = -EINVAL;
		if (!buf || len < 0)
		if (!buf || len < 0)
			goto out;
			goto out;
@@ -320,10 +306,12 @@ int do_syslog(int type, char __user *buf, int len)
		if (!error)
		if (!error)
			error = i;
			error = i;
		break;
		break;
	case 4:		/* Read/clear last kernel messages */
	/* Read/clear last kernel messages */
	case SYSLOG_ACTION_READ_CLEAR:
		do_clear = 1;
		do_clear = 1;
		/* FALL THRU */
		/* FALL THRU */
	case 3:		/* Read last kernel messages */
	/* Read last kernel messages */
	case SYSLOG_ACTION_READ_ALL:
		error = -EINVAL;
		error = -EINVAL;
		if (!buf || len < 0)
		if (!buf || len < 0)
			goto out;
			goto out;
@@ -376,21 +364,25 @@ int do_syslog(int type, char __user *buf, int len)
			}
			}
		}
		}
		break;
		break;
	case 5:		/* Clear ring buffer */
	/* Clear ring buffer */
	case SYSLOG_ACTION_CLEAR:
		logged_chars = 0;
		logged_chars = 0;
		break;
		break;
	case 6:		/* Disable logging to console */
	/* Disable logging to console */
	case SYSLOG_ACTION_CONSOLE_OFF:
		if (saved_console_loglevel == -1)
		if (saved_console_loglevel == -1)
			saved_console_loglevel = console_loglevel;
			saved_console_loglevel = console_loglevel;
		console_loglevel = minimum_console_loglevel;
		console_loglevel = minimum_console_loglevel;
		break;
		break;
	case 7:		/* Enable logging to console */
	/* Enable logging to console */
	case SYSLOG_ACTION_CONSOLE_ON:
		if (saved_console_loglevel != -1) {
		if (saved_console_loglevel != -1) {
			console_loglevel = saved_console_loglevel;
			console_loglevel = saved_console_loglevel;
			saved_console_loglevel = -1;
			saved_console_loglevel = -1;
		}
		}
		break;
		break;
	case 8:		/* Set level of messages printed to console */
	/* Set level of messages printed to console */
	case SYSLOG_ACTION_CONSOLE_LEVEL:
		error = -EINVAL;
		error = -EINVAL;
		if (len < 1 || len > 8)
		if (len < 1 || len > 8)
			goto out;
			goto out;
@@ -401,10 +393,12 @@ int do_syslog(int type, char __user *buf, int len)
		saved_console_loglevel = -1;
		saved_console_loglevel = -1;
		error = 0;
		error = 0;
		break;
		break;
	case 9:		/* Number of chars in the log buffer */
	/* Number of chars in the log buffer */
	case SYSLOG_ACTION_SIZE_UNREAD:
		error = log_end - log_start;
		error = log_end - log_start;
		break;
		break;
	case 10:	/* Size of the log buffer */
	/* Size of the log buffer */
	case SYSLOG_ACTION_SIZE_BUFFER:
		error = log_buf_len;
		error = log_buf_len;
		break;
		break;
	default:
	default:
@@ -417,7 +411,7 @@ int do_syslog(int type, char __user *buf, int len)


SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)
SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)
{
{
	return do_syslog(type, buf, len);
	return do_syslog(type, buf, len, SYSLOG_FROM_CALL);
}
}


/*
/*
Loading