~serge-hallyn/ubuntu/raring/shadow/shadow-userns

« back to all changes in this revision

Viewing changes to debian/patches/userns/08_userns_detect_busy_subids

  • Committer: Serge Hallyn
  • Date: 2013-02-01 21:31:48 UTC
  • Revision ID: serge.hallyn@canonical.com-20130201213148-6ms9125tjn2lngnq
Add patchset by Eric Biederman to support subids for use by unprivileged
users to administer private user namespaces.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From ebiederm@xmission.com  Tue Jan 22 09:19:49 2013
 
2
Return-Path: <ebiederm@xmission.com>
 
3
X-Original-To: serge@hallyn.com
 
4
Delivered-To: serge@hallyn.com
 
5
Received: by mail.hallyn.com (Postfix, from userid 5001)
 
6
        id E0EA3C80F4; Tue, 22 Jan 2013 09:19:49 +0000 (UTC)
 
7
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail
 
8
X-Spam-Level: 
 
9
X-Spam-Status: No, score=-2.2 required=8.0 tests=BAD_ENC_HEADER,BAYES_00,
 
10
        RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1
 
11
Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232])
 
12
        (using TLSv1 with cipher AES256-SHA (256/256 bits))
 
13
        (No client certificate requested)
 
14
        by mail.hallyn.com (Postfix) with ESMTPS id 1A2C7C80D1
 
15
        for <serge@hallyn.com>; Tue, 22 Jan 2013 09:19:46 +0000 (UTC)
 
16
Received: from out03.mta.xmission.com ([166.70.13.233])
 
17
        by out02.mta.xmission.com with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 
18
        (Exim 4.76)
 
19
        (envelope-from <ebiederm@xmission.com>)
 
20
        id 1TxZzX-00006D-G7; Tue, 22 Jan 2013 02:18:03 -0700
 
21
Received: from in02.mta.xmission.com ([166.70.13.52])
 
22
        by out03.mta.xmission.com with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 
23
        (Exim 4.76)
 
24
        (envelope-from <ebiederm@xmission.com>)
 
25
        id 1TxZzV-0005Zh-Qq; Tue, 22 Jan 2013 02:18:02 -0700
 
26
Received: from c-98-207-153-68.hsd1.ca.comcast.net ([98.207.153.68] helo=eric-ThinkPad-X220.xmission.com)
 
27
        by in02.mta.xmission.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16)
 
28
        (Exim 4.76)
 
29
        (envelope-from <ebiederm@xmission.com>)
 
30
        id 1TxZzN-0004ul-H6; Tue, 22 Jan 2013 02:18:01 -0700
 
31
From: ebiederm@xmission.com (Eric W. Biederman)
 
32
To: Nicolas =?utf-8?Q?Fran=C3=A7ois?= <nicolas.francois@centraliens.net>
 
33
Cc: <Pkg-shadow-devel@lists.alioth.debian.org>,  Linux Containers <containers@lists.linux-foundation.org>,  "Michael Kerrisk \(man-pages\)" <mtk.manpages@gmail.com>,  "Serge E. Hallyn" <serge@hallyn.com>
 
34
References: <87d2wxshu0.fsf@xmission.com>
 
35
Date: Tue, 22 Jan 2013 01:17:50 -0800
 
36
In-Reply-To: <87d2wxshu0.fsf@xmission.com> (Eric W. Biederman's message of
 
37
        "Tue, 22 Jan 2013 01:11:19 -0800")
 
38
Message-ID: <87y5flpoe9.fsf@xmission.com>
 
39
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux)
 
40
MIME-Version: 1.0
 
41
Content-Type: text/plain
 
42
X-XM-AID: U2FsdGVkX1/ZWJZMWIVV2ekPIrRQjHLl4Oh/kdyWJUw=
 
43
X-SA-Exim-Connect-IP: 98.207.153.68
 
44
X-SA-Exim-Mail-From: ebiederm@xmission.com
 
45
Subject: [PATCH 08/11] Add support for detecting busy subordinate user ids
 
46
X-SA-Exim-Version: 4.2.1 (built Wed, 14 Nov 2012 14:26:46 -0700)
 
47
X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com)
 
48
X-UID: 2078                                        
 
49
Status: RO
 
50
Content-Length: 2655
 
51
Lines: 83
 
52
 
 
53
 
 
54
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
 
55
---
 
56
 libmisc/user_busy.c |   18 +++++++++++++-----
 
57
 1 files changed, 13 insertions(+), 5 deletions(-)
 
58
 
 
59
Index: shadow/libmisc/user_busy.c
 
60
===================================================================
 
61
--- shadow.orig/libmisc/user_busy.c     2013-02-01 15:27:52.952080357 -0600
 
62
+++ shadow/libmisc/user_busy.c  2013-02-01 15:27:52.948080357 -0600
 
63
@@ -38,11 +38,13 @@
 
64
 #include <stdio.h>
 
65
 #include <sys/types.h>
 
66
 #include <dirent.h>
 
67
+#include <fcntl.h>
 
68
 #include "defines.h"
 
69
 #include "prototypes.h"
 
70
+#include "subordinateio.h"
 
71
 
 
72
 #ifdef __linux__
 
73
-static int check_status (const char *sname, uid_t uid);
 
74
+static int check_status (const char *name, const char *sname, uid_t uid);
 
75
 static int user_busy_processes (const char *name, uid_t uid);
 
76
 #else                          /* !__linux__ */
 
77
 static int user_busy_utmp (const char *name);
 
78
@@ -102,7 +104,7 @@
 
79
 #endif                         /* !__linux__ */
 
80
 
 
81
 #ifdef __linux__
 
82
-static int check_status (const char *sname, uid_t uid)
 
83
+static int check_status (const char *name, const char *sname, uid_t uid)
 
84
 {
 
85
        /* 40: /proc/xxxxxxxxxx/task/xxxxxxxxxx/status + \0 */
 
86
        char status[40];
 
87
@@ -125,7 +127,10 @@
 
88
                                    &ruid, &euid, &suid) == 3) {
 
89
                                if (   (ruid == (unsigned long) uid)
 
90
                                    || (euid == (unsigned long) uid)
 
91
-                                   || (suid == (unsigned long) uid)) {
 
92
+                                   || (suid == (unsigned long) uid)
 
93
+                                   || have_sub_uids(name, ruid, 1)
 
94
+                                   || have_sub_uids(name, euid, 1)
 
95
+                                   || have_sub_uids(name, suid, 1)) {
 
96
                                        (void) fclose (sfile);
 
97
                                        return 1;
 
98
                                }
 
99
@@ -153,6 +158,8 @@
 
100
        struct stat sbroot;
 
101
        struct stat sbroot_process;
 
102
 
 
103
+       sub_uid_open (O_RDONLY);
 
104
+
 
105
        proc = opendir ("/proc");
 
106
        if (proc == NULL) {
 
107
                perror ("opendir /proc");
 
108
@@ -196,7 +203,7 @@
 
109
                        continue;
 
110
                }
 
111
 
 
112
-               if (check_status (tmp_d_name, uid) != 0) {
 
113
+               if (check_status (name, tmp_d_name, uid) != 0) {
 
114
                        (void) closedir (proc);
 
115
                        fprintf (stderr,
 
116
                                 _("%s: user %s is currently used by process %d\n"),
 
117
@@ -216,7 +223,7 @@
 
118
                                if (tid == pid) {
 
119
                                        continue;
 
120
                                }
 
121
-                               if (check_status (task_path+6, uid) != 0) {
 
122
+                               if (check_status (name, task_path+6, uid) != 0) {
 
123
                                        (void) closedir (proc);
 
124
                                        fprintf (stderr,
 
125
                                                 _("%s: user %s is currently used by process %d\n"),
 
126
@@ -231,6 +238,7 @@
 
127
        }
 
128
 
 
129
        (void) closedir (proc);
 
130
+       sub_uid_close();
 
131
        return 0;
 
132
 }
 
133
 #endif                         /* __linux__ */