Skip to content

Commit 2fd4e66

Browse files
author
James Morris
committed
Merge branch 'smack-for-3.16' of git://git.gitorious.org/smack-next/kernel into next
2 parents fab71a9 + ec554fa commit 2fd4e66

5 files changed

Lines changed: 307 additions & 73 deletions

File tree

‎Documentation/security/Smack.txt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ onlycap
204204
these capabilities are effective at for processes with any
205205
label. The value is set by writing the desired label to the
206206
file or cleared by writing "-" to the file.
207+
ptrace
208+
This is used to define the current ptrace policy
209+
0 - default: this is the policy that relies on smack access rules.
210+
For the PTRACE_READ a subject needs to have a read access on
211+
object. For the PTRACE_ATTACH a read-write access is required.
212+
1 - exact: this is the policy that limits PTRACE_ATTACH. Attach is
213+
only allowed when subject's and object's labels are equal.
214+
PTRACE_READ is not affected. Can be overriden with CAP_SYS_PTRACE.
215+
2 - draconian: this policy behaves like the 'exact' above with an
216+
exception that it can't be overriden with CAP_SYS_PTRACE.
207217
revoke-subject
208218
Writing a Smack label here sets the access to '-' for all access
209219
rules with that subject label.

‎security/smack/smack.h‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ struct superblock_smack {
8080

8181
struct socket_smack {
8282
struct smack_known *smk_out; /* outbound label */
83-
char *smk_in; /* inbound label */
84-
char *smk_packet; /* TCP peer label */
83+
struct smack_known *smk_in; /* inbound label */
84+
struct smack_known *smk_packet; /* TCP peer label */
8585
};
8686

8787
/*
@@ -133,7 +133,7 @@ struct smk_port_label {
133133
struct list_head list;
134134
struct sock *smk_sock; /* socket initialized on */
135135
unsigned short smk_port; /* the port number */
136-
char *smk_in; /* incoming label */
136+
struct smack_known *smk_in; /* inbound label */
137137
struct smack_known *smk_out; /* outgoing label */
138138
};
139139

@@ -176,6 +176,14 @@ struct smk_port_label {
176176
*/
177177
#define SMACK_CIPSO_MAXCATNUM 184 /* 23 * 8 */
178178

179+
/*
180+
* Ptrace rules
181+
*/
182+
#define SMACK_PTRACE_DEFAULT 0
183+
#define SMACK_PTRACE_EXACT 1
184+
#define SMACK_PTRACE_DRACONIAN 2
185+
#define SMACK_PTRACE_MAX SMACK_PTRACE_DRACONIAN
186+
179187
/*
180188
* Flags for untraditional access modes.
181189
* It shouldn't be necessary to avoid conflicts with definitions
@@ -225,6 +233,7 @@ struct inode_smack *new_inode_smack(char *);
225233
*/
226234
int smk_access_entry(char *, char *, struct list_head *);
227235
int smk_access(struct smack_known *, char *, int, struct smk_audit_info *);
236+
int smk_tskacc(struct task_smack *, char *, u32, struct smk_audit_info *);
228237
int smk_curacc(char *, u32, struct smk_audit_info *);
229238
struct smack_known *smack_from_secid(const u32);
230239
char *smk_parse_smack(const char *string, int len);
@@ -244,6 +253,7 @@ extern struct smack_known *smack_net_ambient;
244253
extern struct smack_known *smack_onlycap;
245254
extern struct smack_known *smack_syslog_label;
246255
extern const char *smack_cipso_option;
256+
extern int smack_ptrace_rule;
247257

248258
extern struct smack_known smack_known_floor;
249259
extern struct smack_known smack_known_hat;

‎security/smack/smack_access.c‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,21 @@ int smk_access(struct smack_known *subject_known, char *object_label,
192192
}
193193

194194
/**
195-
* smk_curacc - determine if current has a specific access to an object
195+
* smk_tskacc - determine if a task has a specific access to an object
196+
* @tsp: a pointer to the subject task
196197
* @obj_label: a pointer to the object's Smack label
197198
* @mode: the access requested, in "MAY" format
198199
* @a : common audit data
199200
*
200-
* This function checks the current subject label/object label pair
201+
* This function checks the subject task's label/object label pair
201202
* in the access rule list and returns 0 if the access is permitted,
202-
* non zero otherwise. It allows that current may have the capability
203+
* non zero otherwise. It allows that the task may have the capability
203204
* to override the rules.
204205
*/
205-
int smk_curacc(char *obj_label, u32 mode, struct smk_audit_info *a)
206+
int smk_tskacc(struct task_smack *subject, char *obj_label,
207+
u32 mode, struct smk_audit_info *a)
206208
{
207-
struct task_smack *tsp = current_security();
208-
struct smack_known *skp = smk_of_task(tsp);
209+
struct smack_known *skp = smk_of_task(subject);
209210
int may;
210211
int rc;
211212

@@ -219,7 +220,7 @@ int smk_curacc(char *obj_label, u32 mode, struct smk_audit_info *a)
219220
* it can further restrict access.
220221
*/
221222
may = smk_access_entry(skp->smk_known, obj_label,
222-
&tsp->smk_rules);
223+
&subject->smk_rules);
223224
if (may < 0)
224225
goto out_audit;
225226
if ((mode & may) == mode)
@@ -241,6 +242,24 @@ int smk_curacc(char *obj_label, u32 mode, struct smk_audit_info *a)
241242
return rc;
242243
}
243244

245+
/**
246+
* smk_curacc - determine if current has a specific access to an object
247+
* @obj_label: a pointer to the object's Smack label
248+
* @mode: the access requested, in "MAY" format
249+
* @a : common audit data
250+
*
251+
* This function checks the current subject label/object label pair
252+
* in the access rule list and returns 0 if the access is permitted,
253+
* non zero otherwise. It allows that current may have the capability
254+
* to override the rules.
255+
*/
256+
int smk_curacc(char *obj_label, u32 mode, struct smk_audit_info *a)
257+
{
258+
struct task_smack *tsp = current_security();
259+
260+
return smk_tskacc(tsp, obj_label, mode, a);
261+
}
262+
244263
#ifdef CONFIG_AUDIT
245264
/**
246265
* smack_str_from_perm : helper to transalate an int to a
@@ -285,7 +304,10 @@ static void smack_log_callback(struct audit_buffer *ab, void *a)
285304
audit_log_untrustedstring(ab, sad->subject);
286305
audit_log_format(ab, " object=");
287306
audit_log_untrustedstring(ab, sad->object);
288-
audit_log_format(ab, " requested=%s", sad->request);
307+
if (sad->request[0] == '\0')
308+
audit_log_format(ab, " labels_differ");
309+
else
310+
audit_log_format(ab, " requested=%s", sad->request);
289311
}
290312

291313
/**

0 commit comments

Comments
 (0)