Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm...
Linus Torvalds [Tue, 2 Oct 2012 18:11:09 +0000 (11:11 -0700)]
Pull user namespace changes from Eric Biederman:
 "This is a mostly modest set of changes to enable basic user namespace
  support.  This allows the code to code to compile with user namespaces
  enabled and removes the assumption there is only the initial user
  namespace.  Everything is converted except for the most complex of the
  filesystems: autofs4, 9p, afs, ceph, cifs, coda, fuse, gfs2, ncpfs,
  nfs, ocfs2 and xfs as those patches need a bit more review.

  The strategy is to push kuid_t and kgid_t values are far down into
  subsystems and filesystems as reasonable.  Leaving the make_kuid and
  from_kuid operations to happen at the edge of userspace, as the values
  come off the disk, and as the values come in from the network.
  Letting compile type incompatible compile errors (present when user
  namespaces are enabled) guide me to find the issues.

  The most tricky areas have been the places where we had an implicit
  union of uid and gid values and were storing them in an unsigned int.
  Those places were converted into explicit unions.  I made certain to
  handle those places with simple trivial patches.

  Out of that work I discovered we have generic interfaces for storing
  quota by projid.  I had never heard of the project identifiers before.
  Adding full user namespace support for project identifiers accounts
  for most of the code size growth in my git tree.

  Ultimately there will be work to relax privlige checks from
  "capable(FOO)" to "ns_capable(user_ns, FOO)" where it is safe allowing
  root in a user names to do those things that today we only forbid to
  non-root users because it will confuse suid root applications.

  While I was pushing kuid_t and kgid_t changes deep into the audit code
  I made a few other cleanups.  I capitalized on the fact we process
  netlink messages in the context of the message sender.  I removed
  usage of NETLINK_CRED, and started directly using current->tty.

  Some of these patches have also made it into maintainer trees, with no
  problems from identical code from different trees showing up in
  linux-next.

  After reading through all of this code I feel like I might be able to
  win a game of kernel trivial pursuit."

Fix up some fairly trivial conflicts in netfilter uid/git logging code.

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: (107 commits)
  userns: Convert the ufs filesystem to use kuid/kgid where appropriate
  userns: Convert the udf filesystem to use kuid/kgid where appropriate
  userns: Convert ubifs to use kuid/kgid
  userns: Convert squashfs to use kuid/kgid where appropriate
  userns: Convert reiserfs to use kuid and kgid where appropriate
  userns: Convert jfs to use kuid/kgid where appropriate
  userns: Convert jffs2 to use kuid and kgid where appropriate
  userns: Convert hpfs to use kuid and kgid where appropriate
  userns: Convert btrfs to use kuid/kgid where appropriate
  userns: Convert bfs to use kuid/kgid where appropriate
  userns: Convert affs to use kuid/kgid wherwe appropriate
  userns: On alpha modify linux_to_osf_stat to use convert from kuids and kgids
  userns: On ia64 deal with current_uid and current_gid being kuid and kgid
  userns: On ppc convert current_uid from a kuid before printing.
  userns: Convert s390 getting uid and gid system calls to use kuid and kgid
  userns: Convert s390 hypfs to use kuid and kgid where appropriate
  userns: Convert binder ipc to use kuids
  userns: Teach security_path_chown to take kuids and kgids
  userns: Add user namespace support to IMA
  userns: Convert EVM to deal with kuids and kgids in it's hmac computation
  ...

57 files changed:
1  2 
arch/alpha/kernel/osf_sys.c
arch/s390/kernel/compat_linux.c
drivers/net/tun.c
drivers/staging/android/binder.c
drivers/usb/gadget/f_fs.c
drivers/usb/gadget/inode.c
fs/affs/super.c
fs/btrfs/delayed-inode.c
fs/btrfs/inode.c
fs/btrfs/ioctl.c
fs/debugfs/inode.c
fs/ecryptfs/main.c
fs/exofs/inode.c
fs/ext3/super.c
fs/ext4/super.c
fs/gfs2/quota.c
fs/hfs/inode.c
fs/logfs/inode.c
fs/logfs/readwrite.c
fs/namei.c
fs/open.c
fs/quota/dquot.c
fs/reiserfs/inode.c
fs/ubifs/super.c
fs/udf/inode.c
fs/udf/super.c
fs/xattr.c
include/linux/sched.h
include/linux/security.h
include/linux/tty.h
include/net/netns/ipv4.h
include/net/sock.h
include/net/tcp.h
include/net/xfrm.h
init/Kconfig
kernel/pid_namespace.c
kernel/trace/trace.c
kernel/trace/trace.h
net/core/dev.c
net/core/scm.c
net/core/sock.c
net/ipv4/raw.c
net/ipv4/tcp_ipv4.c
net/ipv4/udp.c
net/ipv6/raw.c
net/ipv6/tcp_ipv6.c
net/ipv6/udp.c
net/netfilter/nfnetlink_log.c
net/netfilter/xt_LOG.c
net/netlink/af_netlink.c
net/packet/af_packet.c
net/sched/cls_cgroup.c
net/xfrm/xfrm_policy.c
net/xfrm/xfrm_state.c
net/xfrm/xfrm_user.c
security/keys/key.c
security/keys/keyctl.c

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc fs/affs/super.c
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc fs/ext3/super.c
Simple merge
diff --cc fs/ext4/super.c
Simple merge
diff --cc fs/gfs2/quota.c
Simple merge
diff --cc fs/hfs/inode.c
Simple merge
Simple merge
Simple merge
diff --cc fs/namei.c
Simple merge
diff --cc fs/open.c
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc fs/udf/inode.c
Simple merge
diff --cc fs/udf/super.c
Simple merge
diff --cc fs/xattr.c
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -62,9 -63,10 +63,9 @@@ struct netns_ipv4 
        int sysctl_icmp_ratemask;
        int sysctl_icmp_errors_use_inbound_ifaddr;
  
-       unsigned int sysctl_ping_group_range[2];
+       kgid_t sysctl_ping_group_range[2];
        long sysctl_tcp_mem[3];
  
 -      atomic_t rt_genid;
        atomic_t dev_addr_genid;
  
  #ifdef CONFIG_IP_MROUTE
Simple merge
Simple merge
Simple merge
diff --cc init/Kconfig
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc net/core/dev.c
Simple merge
diff --cc net/core/scm.c
Simple merge
diff --cc net/core/sock.c
Simple merge
diff --cc net/ipv4/raw.c
Simple merge
Simple merge
diff --cc net/ipv4/udp.c
Simple merge
diff --cc net/ipv6/raw.c
Simple merge
Simple merge
diff --cc net/ipv6/udp.c
Simple merge
@@@ -500,14 -501,16 +502,16 @@@ __build_packet_message(struct nfulnl_in
        }
  
        /* UID */
 -      if (skb->sk) {
 -              read_lock_bh(&skb->sk->sk_callback_lock);
 -              if (skb->sk->sk_socket && skb->sk->sk_socket->file) {
 -                      struct file *file = skb->sk->sk_socket->file;
 -                      __be32 uid = htonl(from_kuid_munged(inst->peer_user_ns,
 -                                                          file->f_cred->fsuid));
 -                      __be32 gid = htonl(from_kgid_munged(inst->peer_user_ns,
 -                                                          file->f_cred->fsgid));
 -                      /* need to unlock here since NLA_PUT may goto */
 -                      read_unlock_bh(&skb->sk->sk_callback_lock);
 +      sk = skb->sk;
 +      if (sk && sk->sk_state != TCP_TIME_WAIT) {
 +              read_lock_bh(&sk->sk_callback_lock);
 +              if (sk->sk_socket && sk->sk_socket->file) {
 +                      struct file *file = sk->sk_socket->file;
-                       __be32 uid = htonl(file->f_cred->fsuid);
-                       __be32 gid = htonl(file->f_cred->fsgid);
++                      const struct cred *cred = file->f_cred;
++                      struct user_namespace *user_ns = inst->peer_user_ns;
++                      __be32 uid = htonl(from_kuid_munged(user_ns, cred->fsuid));
++                      __be32 gid = htonl(from_kgid_munged(user_ns, cred->fsgid));
 +                      read_unlock_bh(&sk->sk_callback_lock);
                        if (nla_put_be32(inst->skb, NFULA_UID, uid) ||
                            nla_put_be32(inst->skb, NFULA_GID, gid))
                                goto nla_put_failure;
@@@ -145,19 -145,6 +145,21 @@@ static int dump_tcp_header(struct sbuf
        return 0;
  }
  
 +static void dump_sk_uid_gid(struct sbuff *m, struct sock *sk)
 +{
 +      if (!sk || sk->sk_state == TCP_TIME_WAIT)
 +              return;
 +
 +      read_lock_bh(&sk->sk_callback_lock);
-       if (sk->sk_socket && sk->sk_socket->file)
++      if (sk->sk_socket && sk->sk_socket->file) {
++              const struct cred *cred = sk->sk_socket->file->f_cred;
 +              sb_add(m, "UID=%u GID=%u ",
-                       sk->sk_socket->file->f_cred->fsuid,
-                       sk->sk_socket->file->f_cred->fsgid);
++                      from_kuid_munged(&init_user_ns, cred->fsuid),
++                      from_kgid_munged(&init_user_ns, cred->fsgid));
++      }
 +      read_unlock_bh(&sk->sk_callback_lock);
 +}
 +
  /* One level of recursion won't kill us */
  static void dump_ipv4_packet(struct sbuff *m,
                        const struct nf_loginfo *info,
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge