@@ -221,7 +221,7 @@ static int profile_create_perm(struct aa_profile *profile, int family,
221
221
222
222
static int profile_sk_perm (struct aa_profile * profile ,
223
223
struct apparmor_audit_data * ad ,
224
- u32 request , struct sock * sk )
224
+ u32 request , struct sock * sk , struct path * path )
225
225
{
226
226
struct aa_ruleset * rules = list_first_entry (& profile -> rules ,
227
227
typeof (* rules ),
@@ -231,11 +231,15 @@ static int profile_sk_perm(struct aa_profile *profile,
231
231
232
232
AA_BUG (!profile );
233
233
AA_BUG (!sk );
234
- AA_BUG (is_unix_fs (sk ));
235
234
AA_BUG (profile_unconfined (profile ));
236
235
237
236
state = RULE_MEDIATES_v9NET (rules );
238
237
if (state ) {
238
+ if (is_unix_fs (sk ))
239
+ return unix_fs_perm (ad -> op , request , ad -> subj_cred ,
240
+ & profile -> label ,
241
+ & unix_sk (sk )-> path );
242
+
239
243
state = match_to_sk (rules -> policy , state , request , unix_sk (sk ),
240
244
& p , & ad -> info );
241
245
@@ -261,6 +265,9 @@ static int profile_bind_perm(struct aa_profile *profile, struct sock *sk,
261
265
262
266
state = RULE_MEDIATES_v9NET (rules );
263
267
if (state ) {
268
+ if (is_unix_addr_fs (ad -> net .addr , ad -> net .addrlen ))
269
+ /* under v7-9 fs hook handles bind */
270
+ return 0 ;
264
271
/* bind for abstract socket */
265
272
state = match_to_local (rules -> policy , state , AA_MAY_BIND ,
266
273
sk -> sk_type , sk -> sk_protocol ,
@@ -285,14 +292,18 @@ static int profile_listen_perm(struct aa_profile *profile, struct sock *sk,
285
292
286
293
AA_BUG (!profile );
287
294
AA_BUG (!sk );
288
- AA_BUG (is_unix_fs (sk ));
289
295
AA_BUG (!ad );
290
296
AA_BUG (profile_unconfined (profile ));
291
297
292
298
state = RULE_MEDIATES_v9NET (rules );
293
299
if (state ) {
294
300
__be16 b = cpu_to_be16 (backlog );
295
301
302
+ if (is_unix_fs (sk ))
303
+ return unix_fs_perm (ad -> op , AA_MAY_LISTEN ,
304
+ ad -> subj_cred , & profile -> label ,
305
+ & unix_sk (sk )-> path );
306
+
296
307
state = match_to_cmd (rules -> policy , state , AA_MAY_LISTEN ,
297
308
unix_sk (sk ), CMD_LISTEN , & p , & ad -> info );
298
309
if (state && !p ) {
@@ -319,12 +330,16 @@ static int profile_accept_perm(struct aa_profile *profile,
319
330
320
331
AA_BUG (!profile );
321
332
AA_BUG (!sk );
322
- AA_BUG (is_unix_fs (sk ));
323
333
AA_BUG (!ad );
324
334
AA_BUG (profile_unconfined (profile ));
325
335
326
336
state = RULE_MEDIATES_v9NET (rules );
327
337
if (state ) {
338
+ if (is_unix_fs (sk ))
339
+ return unix_fs_perm (ad -> op , AA_MAY_ACCEPT ,
340
+ ad -> subj_cred , & profile -> label ,
341
+ & unix_sk (sk )-> path );
342
+
328
343
state = match_to_sk (rules -> policy , state , AA_MAY_ACCEPT ,
329
344
unix_sk (sk ), & p , & ad -> info );
330
345
@@ -346,13 +361,16 @@ static int profile_opt_perm(struct aa_profile *profile, u32 request,
346
361
347
362
AA_BUG (!profile );
348
363
AA_BUG (!sk );
349
- AA_BUG (is_unix_fs (sk ));
350
364
AA_BUG (!ad );
351
365
AA_BUG (profile_unconfined (profile ));
352
366
353
367
state = RULE_MEDIATES_v9NET (rules );
354
368
if (state ) {
355
369
__be16 b = cpu_to_be16 (optname );
370
+ if (is_unix_fs (sk ))
371
+ return unix_fs_perm (ad -> op , request ,
372
+ ad -> subj_cred , & profile -> label ,
373
+ & unix_sk (sk )-> path );
356
374
357
375
state = match_to_cmd (rules -> policy , state , request , unix_sk (sk ),
358
376
CMD_OPT , & p , & ad -> info );
@@ -371,8 +389,9 @@ static int profile_opt_perm(struct aa_profile *profile, u32 request,
371
389
372
390
/* null peer_label is allowed, in which case the peer_sk label is used */
373
391
static int profile_peer_perm (struct aa_profile * profile , u32 request ,
374
- struct sock * sk , struct sockaddr_un * peer_addr ,
375
- int peer_addrlen ,
392
+ struct sock * sk , struct path * path ,
393
+ struct sockaddr_un * peer_addr ,
394
+ int peer_addrlen , struct path * peer_path ,
376
395
struct aa_label * peer_label ,
377
396
struct apparmor_audit_data * ad )
378
397
{
@@ -391,6 +410,12 @@ static int profile_peer_perm(struct aa_profile *profile, u32 request,
391
410
if (state ) {
392
411
struct aa_profile * peerp ;
393
412
413
+ if (peer_path )
414
+ return unix_fs_perm (ad -> op , request , ad -> subj_cred ,
415
+ & profile -> label , peer_path );
416
+ else if (path )
417
+ return unix_fs_perm (ad -> op , request , ad -> subj_cred ,
418
+ & profile -> label , path );
394
419
state = match_to_peer (rules -> policy , state , request ,
395
420
unix_sk (sk ),
396
421
peer_addr , peer_addrlen , & p , & ad -> info );
@@ -421,15 +446,18 @@ int aa_unix_create_perm(struct aa_label *label, int family, int type,
421
446
return 0 ;
422
447
}
423
448
424
- int aa_unix_label_sk_perm (const struct cred * subj_cred , struct aa_label * label ,
425
- const char * op , u32 request , struct sock * sk )
449
+ static int aa_unix_label_sk_perm (const struct cred * subj_cred ,
450
+ struct aa_label * label ,
451
+ const char * op , u32 request , struct sock * sk ,
452
+ struct path * path )
426
453
{
427
454
if (!unconfined (label )) {
428
455
struct aa_profile * profile ;
429
456
DEFINE_AUDIT_SK (ad , op , subj_cred , sk );
430
457
431
458
return fn_for_each_confined (label , profile ,
432
- profile_sk_perm (profile , & ad , request , sk ));
459
+ profile_sk_perm (profile , & ad , request , sk ,
460
+ path ));
433
461
}
434
462
return 0 ;
435
463
}
@@ -441,12 +469,9 @@ int aa_unix_sock_perm(const char *op, u32 request, struct socket *sock)
441
469
int error ;
442
470
443
471
label = begin_current_label_crit_section ();
444
- if (is_unix_fs (sock -> sk ))
445
- error = unix_fs_perm (op , request , current_cred (), label ,
446
- & unix_sk (sock -> sk )-> path );
447
- else
448
- error = aa_unix_label_sk_perm (current_cred (), label , op ,
449
- request , sock -> sk );
472
+ error = aa_unix_label_sk_perm (current_cred (), label , op ,
473
+ request , sock -> sk ,
474
+ is_unix_fs (sock -> sk ) ? & unix_sk (sock -> sk )-> path : NULL );
450
475
end_current_label_crit_section (label );
451
476
452
477
return error ;
@@ -476,7 +501,7 @@ int aa_unix_bind_perm(struct socket *sock, struct sockaddr *addr,
476
501
477
502
label = begin_current_label_crit_section ();
478
503
/* fs bind is handled by mknod */
479
- if (!( unconfined (label ) || is_unix_addr_fs ( addr , addrlen ) )) {
504
+ if (!unconfined (label )) {
480
505
DEFINE_AUDIT_SK (ad , OP_BIND , current_cred (), sock -> sk );
481
506
482
507
ad .net .addr = unix_addr (addr );
@@ -510,7 +535,7 @@ int aa_unix_listen_perm(struct socket *sock, int backlog)
510
535
int error = 0 ;
511
536
512
537
label = begin_current_label_crit_section ();
513
- if (!( unconfined (label ) || is_unix_fs ( sock -> sk ) )) {
538
+ if (!unconfined (label )) {
514
539
DEFINE_AUDIT_SK (ad , OP_LISTEN , current_cred (), sock -> sk );
515
540
516
541
error = fn_for_each_confined (label , profile ,
@@ -531,7 +556,7 @@ int aa_unix_accept_perm(struct socket *sock, struct socket *newsock)
531
556
int error = 0 ;
532
557
533
558
label = begin_current_label_crit_section ();
534
- if (!( unconfined (label ) || is_unix_fs ( sock -> sk ) )) {
559
+ if (!unconfined (label )) {
535
560
DEFINE_AUDIT_SK (ad , OP_ACCEPT , current_cred (), sock -> sk );
536
561
537
562
error = fn_for_each_confined (label , profile ,
@@ -564,12 +589,12 @@ int aa_unix_opt_perm(const char *op, u32 request, struct socket *sock,
564
589
int error = 0 ;
565
590
566
591
label = begin_current_label_crit_section ();
567
- if (!( unconfined (label ) || is_unix_fs ( sock -> sk ) )) {
592
+ if (!unconfined (label )) {
568
593
DEFINE_AUDIT_SK (ad , op , current_cred (), sock -> sk );
569
594
570
595
error = fn_for_each_confined (label , profile ,
571
- profile_opt_perm (profile , request ,
572
- sock -> sk , optname , & ad ));
596
+ profile_opt_perm (profile , request , sock -> sk ,
597
+ optname , & ad ));
573
598
}
574
599
end_current_label_crit_section (label );
575
600
@@ -578,8 +603,9 @@ int aa_unix_opt_perm(const char *op, u32 request, struct socket *sock,
578
603
579
604
static int unix_peer_perm (const struct cred * subj_cred ,
580
605
struct aa_label * label , const char * op , u32 request ,
581
- struct sock * sk , struct sockaddr_un * peer_addr ,
582
- int peer_addrlen , struct aa_label * peer_label )
606
+ struct sock * sk , struct path * path ,
607
+ struct sockaddr_un * peer_addr , int peer_addrlen ,
608
+ struct path * peer_path , struct aa_label * peer_label )
583
609
{
584
610
struct aa_profile * profile ;
585
611
DEFINE_AUDIT_SK (ad , op , subj_cred , sk );
@@ -588,8 +614,9 @@ static int unix_peer_perm(const struct cred *subj_cred,
588
614
ad .net .peer .addrlen = peer_addrlen ;
589
615
590
616
return fn_for_each_confined (label , profile ,
591
- profile_peer_perm (profile , request , sk ,
592
- peer_addr , peer_addrlen , peer_label , & ad ));
617
+ profile_peer_perm (profile , request , sk , path ,
618
+ peer_addr , peer_addrlen , peer_path ,
619
+ peer_label , & ad ));
593
620
}
594
621
595
622
/**
@@ -604,27 +631,19 @@ int aa_unix_peer_perm(const struct cred *subj_cred,
604
631
{
605
632
struct unix_sock * peeru = unix_sk (peer_sk );
606
633
struct unix_sock * u = unix_sk (sk );
634
+ int plen ;
635
+ struct sockaddr_un * paddr = aa_sunaddr (unix_sk (peer_sk ), & plen );
607
636
608
637
AA_BUG (!label );
609
638
AA_BUG (!sk );
610
639
AA_BUG (!peer_sk );
611
640
AA_BUG (!peer_label );
612
641
613
- if (is_unix_fs (aa_unix_sk (peeru ))) {
614
- return unix_fs_perm (op , request , subj_cred , label ,
615
- & peeru -> path );
616
- } else if (is_unix_fs (aa_unix_sk (u ))) {
617
- return unix_fs_perm (op , request , subj_cred , label , & u -> path );
618
- } else if (!unconfined (label )) {
619
- int plen ;
620
- struct sockaddr_un * paddr = aa_sunaddr (unix_sk (peer_sk ),
621
- & plen );
622
-
623
- return unix_peer_perm (subj_cred , label , op , request ,
624
- sk , paddr , plen , peer_label );
625
- }
626
-
627
- return 0 ;
642
+ return unix_peer_perm (subj_cred , label , op , request , sk ,
643
+ is_unix_fs (sk ) ? & u -> path : NULL ,
644
+ paddr , plen ,
645
+ is_unix_fs (peer_sk ) ? & peeru -> path : NULL ,
646
+ peer_label );
628
647
}
629
648
630
649
/* This fn is only checked if something has changed in the security
@@ -665,12 +684,9 @@ int aa_unix_file_perm(const struct cred *subj_cred, struct aa_label *label,
665
684
if (is_sk_fs && peer_sk )
666
685
sk_req = request ;
667
686
if (sk_req ) {
668
- if (is_sk_fs )
669
- error = unix_fs_perm (op , sk_req , subj_cred , label ,
670
- & path );
671
- else
672
687
error = aa_unix_label_sk_perm (subj_cred , label , op ,
673
- sk_req , sock -> sk );
688
+ sk_req , sock -> sk ,
689
+ is_sk_fs ? & path : NULL );
674
690
}
675
691
if (!peer_sk )
676
692
goto out ;
@@ -683,7 +699,7 @@ int aa_unix_file_perm(const struct cred *subj_cred, struct aa_label *label,
683
699
if (!is_sk_fs && is_unix_fs (peer_sk )) {
684
700
last_error (error ,
685
701
unix_fs_perm (op , request , subj_cred , label ,
686
- & peer_path ));
702
+ is_unix_fs ( peer_sk ) ? & peer_path : NULL ));
687
703
} else if (!is_sk_fs ) {
688
704
struct aa_sk_ctx * pctx = aa_sock (peer_sk );
689
705
@@ -693,11 +709,18 @@ int aa_unix_file_perm(const struct cred *subj_cred, struct aa_label *label,
693
709
last_error (error ,
694
710
xcheck (unix_peer_perm (subj_cred , label , op ,
695
711
MAY_READ | MAY_WRITE , sock -> sk ,
712
+ is_sk_fs ? & path : NULL ,
696
713
peer_addr , peer_addrlen ,
714
+ is_unix_fs (peer_sk ) ?
715
+ & peer_path : NULL ,
697
716
pctx -> label ),
698
717
unix_peer_perm (file -> f_cred , pctx -> label , op ,
699
718
MAY_READ | MAY_WRITE , peer_sk ,
700
- addr , addrlen , label )));
719
+ is_unix_fs (peer_sk ) ?
720
+ & peer_path : NULL ,
721
+ addr , addrlen ,
722
+ is_sk_fs ? & path : NULL ,
723
+ label )));
701
724
}
702
725
sock_put (peer_sk );
703
726
0 commit comments