Skip to content

Commit b47711b

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/selinux-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/selinux-2.6: selinux: make mls_compute_sid always polyinstantiate security/selinux: constify function pointer tables and fields security: add a secctx_to_secid() hook security: call security_file_permission from rw_verify_area security: remove security_sb_post_mountroot hook Security: remove security.h include from mm.h Security: remove security_file_mmap hook sparse-warnings (NULL as 0). Security: add get, set, and cloning of superblock security information security/selinux: Add missing "space"
2 parents 7556afa + 2e08c0c commit b47711b

File tree

15 files changed

+642
-341
lines changed

15 files changed

+642
-341
lines changed

fs/compat.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,10 +1104,6 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
11041104
if (ret < 0)
11051105
goto out;
11061106

1107-
ret = security_file_permission(file, type == READ ? MAY_READ:MAY_WRITE);
1108-
if (ret)
1109-
goto out;
1110-
11111107
fnv = NULL;
11121108
if (type == READ) {
11131109
fn = file->f_op->read;

fs/read_write.c

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,27 @@ int rw_verify_area(int read_write, struct file *file, loff_t *ppos, size_t count
197197
{
198198
struct inode *inode;
199199
loff_t pos;
200+
int retval = -EINVAL;
200201

201202
inode = file->f_path.dentry->d_inode;
202203
if (unlikely((ssize_t) count < 0))
203-
goto Einval;
204+
return retval;
204205
pos = *ppos;
205206
if (unlikely((pos < 0) || (loff_t) (pos + count) < 0))
206-
goto Einval;
207+
return retval;
207208

208209
if (unlikely(inode->i_flock && mandatory_lock(inode))) {
209-
int retval = locks_mandatory_area(
210+
retval = locks_mandatory_area(
210211
read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE,
211212
inode, file, pos, count);
212213
if (retval < 0)
213214
return retval;
214215
}
216+
retval = security_file_permission(file,
217+
read_write == READ ? MAY_READ : MAY_WRITE);
218+
if (retval)
219+
return retval;
215220
return count > MAX_RW_COUNT ? MAX_RW_COUNT : count;
216-
217-
Einval:
218-
return -EINVAL;
219221
}
220222

221223
static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
@@ -267,18 +269,15 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
267269
ret = rw_verify_area(READ, file, pos, count);
268270
if (ret >= 0) {
269271
count = ret;
270-
ret = security_file_permission (file, MAY_READ);
271-
if (!ret) {
272-
if (file->f_op->read)
273-
ret = file->f_op->read(file, buf, count, pos);
274-
else
275-
ret = do_sync_read(file, buf, count, pos);
276-
if (ret > 0) {
277-
fsnotify_access(file->f_path.dentry);
278-
add_rchar(current, ret);
279-
}
280-
inc_syscr(current);
272+
if (file->f_op->read)
273+
ret = file->f_op->read(file, buf, count, pos);
274+
else
275+
ret = do_sync_read(file, buf, count, pos);
276+
if (ret > 0) {
277+
fsnotify_access(file->f_path.dentry);
278+
add_rchar(current, ret);
281279
}
280+
inc_syscr(current);
282281
}
283282

284283
return ret;
@@ -325,18 +324,15 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
325324
ret = rw_verify_area(WRITE, file, pos, count);
326325
if (ret >= 0) {
327326
count = ret;
328-
ret = security_file_permission (file, MAY_WRITE);
329-
if (!ret) {
330-
if (file->f_op->write)
331-
ret = file->f_op->write(file, buf, count, pos);
332-
else
333-
ret = do_sync_write(file, buf, count, pos);
334-
if (ret > 0) {
335-
fsnotify_modify(file->f_path.dentry);
336-
add_wchar(current, ret);
337-
}
338-
inc_syscw(current);
327+
if (file->f_op->write)
328+
ret = file->f_op->write(file, buf, count, pos);
329+
else
330+
ret = do_sync_write(file, buf, count, pos);
331+
if (ret > 0) {
332+
fsnotify_modify(file->f_path.dentry);
333+
add_wchar(current, ret);
339334
}
335+
inc_syscw(current);
340336
}
341337

342338
return ret;
@@ -603,9 +599,6 @@ static ssize_t do_readv_writev(int type, struct file *file,
603599
ret = rw_verify_area(type, file, pos, tot_len);
604600
if (ret < 0)
605601
goto out;
606-
ret = security_file_permission(file, type == READ ? MAY_READ : MAY_WRITE);
607-
if (ret)
608-
goto out;
609602

610603
fnv = NULL;
611604
if (type == READ) {
@@ -737,10 +730,6 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
737730
goto fput_in;
738731
count = retval;
739732

740-
retval = security_file_permission (in_file, MAY_READ);
741-
if (retval)
742-
goto fput_in;
743-
744733
/*
745734
* Get output file, and verify that it is ok..
746735
*/
@@ -759,10 +748,6 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
759748
goto fput_out;
760749
count = retval;
761750

762-
retval = security_file_permission (out_file, MAY_WRITE);
763-
if (retval)
764-
goto fput_out;
765-
766751
if (!max)
767752
max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
768753

fs/splice.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,6 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
908908
if (unlikely(ret < 0))
909909
return ret;
910910

911-
ret = security_file_permission(out, MAY_WRITE);
912-
if (unlikely(ret < 0))
913-
return ret;
914-
915911
return out->f_op->splice_write(pipe, out, ppos, len, flags);
916912
}
917913

@@ -934,10 +930,6 @@ static long do_splice_to(struct file *in, loff_t *ppos,
934930
if (unlikely(ret < 0))
935931
return ret;
936932

937-
ret = security_file_permission(in, MAY_READ);
938-
if (unlikely(ret < 0))
939-
return ret;
940-
941933
return in->f_op->splice_read(in, ppos, pipe, len, flags);
942934
}
943935

include/linux/mm.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/prio_tree.h>
1313
#include <linux/debug_locks.h>
1414
#include <linux/mm_types.h>
15-
#include <linux/security.h>
1615

1716
struct mempolicy;
1817
struct anon_vma;
@@ -34,6 +33,8 @@ extern int sysctl_legacy_va_layout;
3433
#define sysctl_legacy_va_layout 0
3534
#endif
3635

36+
extern unsigned long mmap_min_addr;
37+
3738
#include <asm/page.h>
3839
#include <asm/pgtable.h>
3940
#include <asm/processor.h>

include/linux/security.h

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
#include <linux/xfrm.h>
3535
#include <net/flow.h>
3636

37+
/* only a char in selinux superblock security struct flags */
38+
#define FSCONTEXT_MNT 0x01
39+
#define CONTEXT_MNT 0x02
40+
#define ROOTCONTEXT_MNT 0x04
41+
#define DEFCONTEXT_MNT 0x08
42+
3743
/*
3844
* Bounding set
3945
*/
@@ -243,9 +249,6 @@ struct request_sock;
243249
* @mnt contains the mounted file system.
244250
* @flags contains the new filesystem flags.
245251
* @data contains the filesystem-specific data.
246-
* @sb_post_mountroot:
247-
* Update the security module's state when the root filesystem is mounted.
248-
* This hook is only called if the mount was successful.
249252
* @sb_post_addmount:
250253
* Update the security module's state when a filesystem is mounted.
251254
* This hook is called any time a mount is successfully grafetd to
@@ -261,6 +264,22 @@ struct request_sock;
261264
* Update module state after a successful pivot.
262265
* @old_nd contains the nameidata structure for the old root.
263266
* @new_nd contains the nameidata structure for the new root.
267+
* @sb_get_mnt_opts:
268+
* Get the security relevant mount options used for a superblock
269+
* @sb the superblock to get security mount options from
270+
* @mount_options array for pointers to mount options
271+
* @mount_flags array of ints specifying what each mount options is
272+
* @num_opts number of options in the arrays
273+
* @sb_set_mnt_opts:
274+
* Set the security relevant mount options used for a superblock
275+
* @sb the superblock to set security mount options for
276+
* @mount_options array for pointers to mount options
277+
* @mount_flags array of ints specifying what each mount options is
278+
* @num_opts number of options in the arrays
279+
* @sb_clone_mnt_opts:
280+
* Copy all security options from a given superblock to another
281+
* @oldsb old superblock which contain information to clone
282+
* @newsb new superblock which needs filled in
264283
*
265284
* Security hooks for inode operations.
266285
*
@@ -1183,6 +1202,10 @@ struct request_sock;
11831202
* Convert secid to security context.
11841203
* @secid contains the security ID.
11851204
* @secdata contains the pointer that stores the converted security context.
1205+
* @secctx_to_secid:
1206+
* Convert security context to secid.
1207+
* @secid contains the pointer to the generated security ID.
1208+
* @secdata contains the security context.
11861209
*
11871210
* @release_secctx:
11881211
* Release the security context.
@@ -1235,13 +1258,19 @@ struct security_operations {
12351258
void (*sb_umount_busy) (struct vfsmount * mnt);
12361259
void (*sb_post_remount) (struct vfsmount * mnt,
12371260
unsigned long flags, void *data);
1238-
void (*sb_post_mountroot) (void);
12391261
void (*sb_post_addmount) (struct vfsmount * mnt,
12401262
struct nameidata * mountpoint_nd);
12411263
int (*sb_pivotroot) (struct nameidata * old_nd,
12421264
struct nameidata * new_nd);
12431265
void (*sb_post_pivotroot) (struct nameidata * old_nd,
12441266
struct nameidata * new_nd);
1267+
int (*sb_get_mnt_opts) (const struct super_block *sb,
1268+
char ***mount_options, int **flags,
1269+
int *num_opts);
1270+
int (*sb_set_mnt_opts) (struct super_block *sb, char **mount_options,
1271+
int *flags, int num_opts);
1272+
void (*sb_clone_mnt_opts) (const struct super_block *oldsb,
1273+
struct super_block *newsb);
12451274

12461275
int (*inode_alloc_security) (struct inode *inode);
12471276
void (*inode_free_security) (struct inode *inode);
@@ -1371,6 +1400,7 @@ struct security_operations {
13711400
int (*getprocattr)(struct task_struct *p, char *name, char **value);
13721401
int (*setprocattr)(struct task_struct *p, char *name, void *value, size_t size);
13731402
int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
1403+
int (*secctx_to_secid)(char *secdata, u32 seclen, u32 *secid);
13741404
void (*release_secctx)(char *secdata, u32 seclen);
13751405

13761406
#ifdef CONFIG_SECURITY_NETWORK
@@ -1495,10 +1525,16 @@ int security_sb_umount(struct vfsmount *mnt, int flags);
14951525
void security_sb_umount_close(struct vfsmount *mnt);
14961526
void security_sb_umount_busy(struct vfsmount *mnt);
14971527
void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *data);
1498-
void security_sb_post_mountroot(void);
14991528
void security_sb_post_addmount(struct vfsmount *mnt, struct nameidata *mountpoint_nd);
15001529
int security_sb_pivotroot(struct nameidata *old_nd, struct nameidata *new_nd);
15011530
void security_sb_post_pivotroot(struct nameidata *old_nd, struct nameidata *new_nd);
1531+
int security_sb_get_mnt_opts(const struct super_block *sb, char ***mount_options,
1532+
int **flags, int *num_opts);
1533+
int security_sb_set_mnt_opts(struct super_block *sb, char **mount_options,
1534+
int *flags, int num_opts);
1535+
void security_sb_clone_mnt_opts(const struct super_block *oldsb,
1536+
struct super_block *newsb);
1537+
15021538
int security_inode_alloc(struct inode *inode);
15031539
void security_inode_free(struct inode *inode);
15041540
int security_inode_init_security(struct inode *inode, struct inode *dir,
@@ -1603,6 +1639,7 @@ int security_setprocattr(struct task_struct *p, char *name, void *value, size_t
16031639
int security_netlink_send(struct sock *sk, struct sk_buff *skb);
16041640
int security_netlink_recv(struct sk_buff *skb, int cap);
16051641
int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
1642+
int security_secctx_to_secid(char *secdata, u32 seclen, u32 *secid);
16061643
void security_release_secctx(char *secdata, u32 seclen);
16071644

16081645
#else /* CONFIG_SECURITY */
@@ -1777,9 +1814,6 @@ static inline void security_sb_post_remount (struct vfsmount *mnt,
17771814
unsigned long flags, void *data)
17781815
{ }
17791816

1780-
static inline void security_sb_post_mountroot (void)
1781-
{ }
1782-
17831817
static inline void security_sb_post_addmount (struct vfsmount *mnt,
17841818
struct nameidata *mountpoint_nd)
17851819
{ }
@@ -2266,7 +2300,7 @@ static inline struct dentry *securityfs_create_file(const char *name,
22662300
mode_t mode,
22672301
struct dentry *parent,
22682302
void *data,
2269-
struct file_operations *fops)
2303+
const struct file_operations *fops)
22702304
{
22712305
return ERR_PTR(-ENODEV);
22722306
}
@@ -2280,6 +2314,13 @@ static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *secle
22802314
return -EOPNOTSUPP;
22812315
}
22822316

2317+
static inline int security_secctx_to_secid(char *secdata,
2318+
u32 seclen,
2319+
u32 *secid)
2320+
{
2321+
return -EOPNOTSUPP;
2322+
}
2323+
22832324
static inline void security_release_secctx(char *secdata, u32 seclen)
22842325
{
22852326
}

init/do_mounts.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,5 @@ void __init prepare_namespace(void)
378378
out:
379379
sys_mount(".", "/", NULL, MS_MOVE, NULL);
380380
sys_chroot(".");
381-
security_sb_post_mountroot();
382381
}
383382

mm/mmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ static inline int expand_downwards(struct vm_area_struct *vma,
16201620
return -ENOMEM;
16211621

16221622
address &= PAGE_MASK;
1623-
error = security_file_mmap(0, 0, 0, 0, address, 1);
1623+
error = security_file_mmap(NULL, 0, 0, 0, address, 1);
16241624
if (error)
16251625
return error;
16261626

@@ -1941,7 +1941,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
19411941
if (is_hugepage_only_range(mm, addr, len))
19421942
return -EINVAL;
19431943

1944-
error = security_file_mmap(0, 0, 0, 0, addr, 1);
1944+
error = security_file_mmap(NULL, 0, 0, 0, addr, 1);
19451945
if (error)
19461946
return error;
19471947

0 commit comments

Comments
 (0)