26 Oct, 2010

1 commit


23 Oct, 2010

1 commit

  • * 'llseek' of git://git.kernel.org/pub/scm/linux/kernel/git/arnd/bkl:
    vfs: make no_llseek the default
    vfs: don't use BKL in default_llseek
    llseek: automatically add .llseek fop
    libfs: use generic_file_llseek for simple_attr
    mac80211: disallow seeks in minstrel debug code
    lirc: make chardev nonseekable
    viotape: use noop_llseek
    raw: use explicit llseek file operations
    ibmasmfs: use generic_file_llseek
    spufs: use llseek in all file operations
    arm/omap: use generic_file_llseek in iommu_debug
    lkdtm: use generic_file_llseek in debugfs
    net/wireless: use generic_file_llseek in debugfs
    drm: use noop_llseek

    Linus Torvalds
     

21 Oct, 2010

2 commits


15 Oct, 2010

1 commit

  • All file_operations should get a .llseek operation so we can make
    nonseekable_open the default for future file operations without a
    .llseek pointer.

    The three cases that we can automatically detect are no_llseek, seq_lseek
    and default_llseek. For cases where we can we can automatically prove that
    the file offset is always ignored, we use noop_llseek, which maintains
    the current behavior of not returning an error from a seek.

    New drivers should normally not use noop_llseek but instead use no_llseek
    and call nonseekable_open at open time. Existing drivers can be converted
    to do the same when the maintainer knows for certain that no user code
    relies on calling seek on the device file.

    The generated code is often incorrectly indented and right now contains
    comments that clarify for each added line why a specific variant was
    chosen. In the version that gets submitted upstream, the comments will
    be gone and I will manually fix the indentation, because there does not
    seem to be a way to do that using coccinelle.

    Some amount of new code is currently sitting in linux-next that should get
    the same modifications, which I will do at the end of the merge window.

    Many thanks to Julia Lawall for helping me learn to write a semantic
    patch that does all this.

    ===== begin semantic patch =====
    // This adds an llseek= method to all file operations,
    // as a preparation for making no_llseek the default.
    //
    // The rules are
    // - use no_llseek explicitly if we do nonseekable_open
    // - use seq_lseek for sequential files
    // - use default_llseek if we know we access f_pos
    // - use noop_llseek if we know we don't access f_pos,
    // but we still want to allow users to call lseek
    //
    @ open1 exists @
    identifier nested_open;
    @@
    nested_open(...)
    {

    }

    @ open exists@
    identifier open_f;
    identifier i, f;
    identifier open1.nested_open;
    @@
    int open_f(struct inode *i, struct file *f)
    {

    }

    @ read disable optional_qualifier exists @
    identifier read_f;
    identifier f, p, s, off;
    type ssize_t, size_t, loff_t;
    expression E;
    identifier func;
    @@
    ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
    {

    }

    @ read_no_fpos disable optional_qualifier exists @
    identifier read_f;
    identifier f, p, s, off;
    type ssize_t, size_t, loff_t;
    @@
    ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
    {
    ... when != off
    }

    @ write @
    identifier write_f;
    identifier f, p, s, off;
    type ssize_t, size_t, loff_t;
    expression E;
    identifier func;
    @@
    ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
    {

    }

    @ write_no_fpos @
    identifier write_f;
    identifier f, p, s, off;
    type ssize_t, size_t, loff_t;
    @@
    ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
    {
    ... when != off
    }

    @ fops0 @
    identifier fops;
    @@
    struct file_operations fops = {
    ...
    };

    @ has_llseek depends on fops0 @
    identifier fops0.fops;
    identifier llseek_f;
    @@
    struct file_operations fops = {
    ...
    .llseek = llseek_f,
    ...
    };

    @ has_read depends on fops0 @
    identifier fops0.fops;
    identifier read_f;
    @@
    struct file_operations fops = {
    ...
    .read = read_f,
    ...
    };

    @ has_write depends on fops0 @
    identifier fops0.fops;
    identifier write_f;
    @@
    struct file_operations fops = {
    ...
    .write = write_f,
    ...
    };

    @ has_open depends on fops0 @
    identifier fops0.fops;
    identifier open_f;
    @@
    struct file_operations fops = {
    ...
    .open = open_f,
    ...
    };

    // use no_llseek if we call nonseekable_open
    ////////////////////////////////////////////
    @ nonseekable1 depends on !has_llseek && has_open @
    identifier fops0.fops;
    identifier nso ~= "nonseekable_open";
    @@
    struct file_operations fops = {
    ... .open = nso, ...
    +.llseek = no_llseek, /* nonseekable */
    };

    @ nonseekable2 depends on !has_llseek @
    identifier fops0.fops;
    identifier open.open_f;
    @@
    struct file_operations fops = {
    ... .open = open_f, ...
    +.llseek = no_llseek, /* open uses nonseekable */
    };

    // use seq_lseek for sequential files
    /////////////////////////////////////
    @ seq depends on !has_llseek @
    identifier fops0.fops;
    identifier sr ~= "seq_read";
    @@
    struct file_operations fops = {
    ... .read = sr, ...
    +.llseek = seq_lseek, /* we have seq_read */
    };

    // use default_llseek if there is a readdir
    ///////////////////////////////////////////
    @ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier readdir_e;
    @@
    // any other fop is used that changes pos
    struct file_operations fops = {
    ... .readdir = readdir_e, ...
    +.llseek = default_llseek, /* readdir is present */
    };

    // use default_llseek if at least one of read/write touches f_pos
    /////////////////////////////////////////////////////////////////
    @ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier read.read_f;
    @@
    // read fops use offset
    struct file_operations fops = {
    ... .read = read_f, ...
    +.llseek = default_llseek, /* read accesses f_pos */
    };

    @ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier write.write_f;
    @@
    // write fops use offset
    struct file_operations fops = {
    ... .write = write_f, ...
    + .llseek = default_llseek, /* write accesses f_pos */
    };

    // Use noop_llseek if neither read nor write accesses f_pos
    ///////////////////////////////////////////////////////////

    @ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier read_no_fpos.read_f;
    identifier write_no_fpos.write_f;
    @@
    // write fops use offset
    struct file_operations fops = {
    ...
    .write = write_f,
    .read = read_f,
    ...
    +.llseek = noop_llseek, /* read and write both use no f_pos */
    };

    @ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier write_no_fpos.write_f;
    @@
    struct file_operations fops = {
    ... .write = write_f, ...
    +.llseek = noop_llseek, /* write uses no f_pos */
    };

    @ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier read_no_fpos.read_f;
    @@
    struct file_operations fops = {
    ... .read = read_f, ...
    +.llseek = noop_llseek, /* read uses no f_pos */
    };

    @ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    @@
    struct file_operations fops = {
    ...
    +.llseek = noop_llseek, /* no read or write fn */
    };
    ===== End semantic patch =====

    Signed-off-by: Arnd Bergmann
    Cc: Julia Lawall
    Cc: Christoph Hellwig

    Arnd Bergmann
     

08 Sep, 2010

4 commits

  • The locking for profile namespace removal is wrong, when removing a
    profile namespace, it needs to be removed from its parent's list.
    Lock the parent of namespace list instead of the namespace being removed.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • As per Dan Carpenter
    If we have a ns name without a following profile then in the original
    code it did "*ns_name = &name[1];". "name" is NULL so "*ns_name" is
    0x1. That isn't useful and could cause an oops when this function is
    called from aa_remove_profiles().

    Beyond this the assignment of the namespace name was wrong in the case
    where the profile name was provided as it was being set to &name[1]
    after name = skip_spaces(split + 1);

    Move the ns_name assignment before updating name for the split and
    also add skip_spaces, making the interface more robust.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • 2.6.36 introduced the abilitiy to specify the task that is having its
    rlimits set. Update mediation to ensure that confined tasks can only
    set their own group_leader as expected by current policy.

    Add TODO note about extending policy to support setting other tasks
    rlimits.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • The 2.6.36 kernel has refactored __d_path() so that it no longer appends
    " (deleted)" to unlinked paths. So drop the hack that was used to detect
    and remove the appended string.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     

19 Aug, 2010

1 commit

  • * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
    fs: brlock vfsmount_lock
    fs: scale files_lock
    lglock: introduce special lglock and brlock spin locks
    tty: fix fu_list abuse
    fs: cleanup files_lock locking
    fs: remove extra lookup in __lookup_hash
    fs: fs_struct rwlock to spinlock
    apparmor: use task path helpers
    fs: dentry allocation consolidation
    fs: fix do_lookup false negative
    mbcache: Limit the maximum number of cache entries
    hostfs ->follow_link() braino
    hostfs: dumb (and usually harmless) tpyo - strncpy instead of strlcpy
    remove SWRITE* I/O types
    kill BH_Ordered flag
    vfs: update ctime when changing the file's permission by setfacl
    cramfs: only unlock new inodes
    fix reiserfs_evict_inode end_writeback second call

    Linus Torvalds
     

18 Aug, 2010

1 commit


17 Aug, 2010

1 commit

  • After rlimits tree was merged we get the following errors:
    security/apparmor/lsm.c:663:2: warning: initialization from incompatible pointer type

    It is because AppArmor was merged in the meantime, but uses the old
    prototype. So fix it by adding struct task_struct as a first parameter
    of apparmor_task_setrlimit.

    NOTE that this is ONLY a compilation warning fix (and crashes caused
    by that). It needs proper handling in AppArmor depending on who is the
    'task'.

    Signed-off-by: Jiri Slaby
    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    Jiri Slaby
     

11 Aug, 2010

1 commit

  • Fixes these build errors:
    security/apparmor/lsm.c:701: error: 'param_ops_aabool' undeclared here (not in a function)
    security/apparmor/lsm.c:721: error: 'param_ops_aalockpolicy' undeclared here (not in a function)
    security/apparmor/lsm.c:729: error: 'param_ops_aauint' undeclared here (not in a function)

    Signed-off-by: Stephen Rothwell
    Signed-off-by: John Johansen
    Signed-off-by: Rusty Russell

    Stephen Rothwell
     

05 Aug, 2010

1 commit

  • SECURITY_APPARMOR should depend on NET since AUDIT needs
    (depends on) NET.

    Fixes 70-80 errors that occur when CONFIG_NET is not enabled,
    but APPARMOR selects AUDIT without qualification. E.g.:

    audit.c:(.text+0x33361): undefined reference to `netlink_unicast'
    (.text+0x333df): undefined reference to `netlink_unicast'
    audit.c:(.text+0x3341d): undefined reference to `skb_queue_tail'
    audit.c:(.text+0x33424): undefined reference to `kfree_skb'
    audit.c:(.text+0x334cb): undefined reference to `kfree_skb'
    audit.c:(.text+0x33597): undefined reference to `skb_put'
    audit.c:(.text+0x3369b): undefined reference to `__alloc_skb'
    audit.c:(.text+0x336d7): undefined reference to `kfree_skb'
    (.text+0x3374c): undefined reference to `__alloc_skb'
    auditfilter.c:(.text+0x35305): undefined reference to `skb_queue_tail'
    lsm_audit.c:(.text+0x2873): undefined reference to `init_net'
    lsm_audit.c:(.text+0x2878): undefined reference to `dev_get_by_index'

    Signed-off-by: Randy Dunlap
    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    Randy Dunlap
     

02 Aug, 2010

14 commits

  • Fix build warnings for non-const use of get_task_cred.

    Signed-off-by: James Morris

    James Morris
     
  • Kconfig and Makefiles to enable configuration and building of AppArmor.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • Remove extraneous path_truncate arguments from the AppArmor hook,
    as they've been removed from the LSM API.

    Signed-off-by: James Morris

    James Morris
     
  • The basic routines and defines for AppArmor policy. AppArmor policy
    is defined by a few basic components.
    profiles - the basic unit of confinement contain all the information
    to enforce policy on a task

    Profiles tend to be named after an executable that they
    will attach to but this is not required.
    namespaces - a container for a set of profiles that will be used
    during attachment and transitions between profiles.
    sids - which provide a unique id for each profile

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • AppArmor policy is loaded in a platform independent flattened binary
    stream. Verify and unpack the data converting it to the internal
    format needed for enforcement.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • ipc:
    AppArmor ipc is currently limited to mediation done by file mediation
    and basic ptrace tests. Improved mediation is a wip.

    rlimits:
    AppArmor provides basic abilities to set and control rlimits at
    a per profile level. Only resources specified in a profile are controled
    or set. AppArmor rules set the hard limit to a value
    Signed-off-by: James Morris

    John Johansen
     
  • AppArmor hooks to interface with the LSM, module parameters and module
    initialization.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • AppArmor routines for controling domain transitions, which can occur at
    exec or through self directed change_profile/change_hat calls.

    Unconfined tasks are checked at exec against the profiles in the confining
    profile namespace to determine if a profile should be attached to the task.

    Confined tasks execs are controlled by the profile which provides rules
    determining which execs are allowed and if so which profiles should be
    transitioned to.

    Self directed domain transitions allow a task to request transition
    to a given profile. If the transition is allowed then the profile will
    be applied, either immeditately or at exec time depending on the request.
    Immeditate self directed transitions have several security limitations
    but have uses in setting up stub transition profiles and other limited
    cases.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • AppArmor does files enforcement via pathname matching. Matching is done
    at file open using a dfa match engine. Permission is against the final
    file object not parent directories, ie. the traversal of directories
    as part of the file match is implicitly allowed. In the case of nonexistant
    files (creation) permissions are checked against the target file not the
    directory. eg. In case of creating the file /dir/new, permissions are
    checked against the match /dir/new not against /dir/.

    The permissions for matches are currently stored in the dfa accept table,
    but this will change to allow for dfa reuse and also to allow for sharing
    of wider accept states.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • The /proc//attr/* interface is used for process introspection and
    commands. While the apparmorfs interface is used for global introspection
    and loading and removing policy.

    The interface currently only contains the files necessary for loading
    policy, and will be extended in the future to include sysfs style
    single per file introspection inteface.

    The old AppArmor 2.4 interface files have been removed into a compatibility
    patch, that distros can use to maintain backwards compatibility.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • A basic dfa matching engine based off the dfa engine in the Dragon
    Book. It uses simple row comb compression with a check field.

    This allows AppArmor to do pattern matching in linear time, and also
    avoids stack issues that an nfa based engine may have. The dfa
    engine uses a byte based comparison, with all values being valid.
    Any potential character encoding are handled user side when the dfa
    tables are created. By convention AppArmor uses \0 to separate two
    dependent path matches since \0 is not a valid path character
    (this is done in the link permission check).

    The dfa tables are generated in user space and are verified at load
    time to be internally consistent.

    There are several future improvements planned for the dfa engine:
    * The dfa engine may be converted to a hybrid nfa-dfa engine, with
    a fixed size limited stack. This would allow for size time
    tradeoffs, by inserting limited nfa states to help control
    state explosion that can occur with dfas.
    * The dfa engine may pickup the ability to do limited dynamic
    variable matching, instead of fixing all variables at policy
    load time.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • AppArmor contexts attach profiles and state to tasks, files, etc. when
    a direct profile reference is not sufficient.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • Update lsm_audit for AppArmor specific data, and add the core routines for
    AppArmor uses for auditing.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     
  • Miscellaneous functions and defines needed by AppArmor, including
    the base path resolution routines.

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen