-
Notifications
You must be signed in to change notification settings - Fork 3
/
kernel.patch.diff
2449 lines (2384 loc) · 69.9 KB
/
kernel.patch.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/linux-stable/drivers/net/ppp/ppp_generic.c b/linux-stable/drivers/net/ppp/ppp_generic.c
index 5c05572..12e9fb7 100644
--- a/linux-stable/drivers/net/ppp/ppp_generic.c
+++ b/linux-stable/drivers/net/ppp/ppp_generic.c
@@ -366,8 +366,8 @@ static int ppp_open(struct inode *inode, struct file *file)
/*
* This could (should?) be enforced by the permissions on /dev/ppp.
*/
- if (!capable(CAP_NET_ADMIN))
- return -EPERM;
+// if (!capable(CAP_NET_ADMIN))
+// return -EPERM;
return 0;
}
diff --git a/linux-stable/fs/exec.c b/linux-stable/fs/exec.c
index 574cf4d..9772ee5 100644
--- a/linux-stable/fs/exec.c
+++ b/linux-stable/fs/exec.c
@@ -1475,6 +1475,8 @@ static int do_execve_common(const char *filename,
int retval;
const struct cred *cred = current_cred();
+// Bhushan: add check to see if task was setuid and current exec is allowed. send cred. read the old cred and is setuid from the security field of task.
+
/*
* We move the actual failure in case of RLIMIT_NPROC excess from
* set*uid() to execve() because too many poorly written programs
@@ -1515,6 +1517,13 @@ static int do_execve_common(const char *filename,
if (IS_ERR(file))
goto out_unmark;
+#ifdef CONFIG_PROTEGO_SECURITY
+ if(security_exec_on_setuid_allowed(cred->euid, file))
+ {
+ retval = -EPERM;
+ goto out_unmark;
+ }
+#endif
sched_exec();
bprm->file = file;
diff --git a/linux-stable/fs/namespace.c b/linux-stable/fs/namespace.c
index 4d31f73..281dc44 100644
--- a/linux-stable/fs/namespace.c
+++ b/linux-stable/fs/namespace.c
@@ -1248,6 +1248,8 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
struct mount *mnt;
int retval;
int lookup_flags = 0;
+ const struct cred *curr_cred = current_cred();
+ char *user_path;
if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
return -EINVAL;
@@ -1266,9 +1268,15 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
goto dput_and_out;
retval = -EPERM;
+ user_path = (char *)vmalloc(strlen(name)+1);
+ memset(user_path, 0, strlen(name)+1);
+ copy_from_user(user_path, name, strlen(name)+1);
+ if (security_umount_allowed(user_path,curr_cred->euid))
+ goto dput_and_out;
+#ifndef CONFIG_PROTEGO_SECURITY
if (!capable(CAP_SYS_ADMIN))
goto dput_and_out;
-
+#endif
retval = do_umount(mnt, flags);
dput_and_out:
/* we mustn't call path_put() as that would clear mnt_expiry_mark */
@@ -2405,6 +2413,7 @@ SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
char *kernel_dir;
char *kernel_dev;
unsigned long data_page;
+ const struct cred *curr_cred = current_cred();
ret = copy_mount_string(type, &kernel_type);
if (ret < 0)
@@ -2424,6 +2433,10 @@ SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
if (ret < 0)
goto out_data;
+ ret = security_mount_allowed(kernel_dev,kernel_dir,curr_cred->euid);
+ if (ret != 0)
+ goto out_data;
+
ret = do_mount(kernel_dev, kernel_dir, kernel_type, flags,
(void *) data_page);
diff --git a/linux-stable/fs/open.c b/linux-stable/fs/open.c
index e1f2cdb..50f3bf5 100644
--- a/linux-stable/fs/open.c
+++ b/linux-stable/fs/open.c
@@ -947,9 +947,22 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
int lookup = build_open_flags(flags, mode, &op);
char *tmp = getname(filename);
int fd = PTR_ERR(tmp);
+ const struct cred *cred = current_cred();
if (!IS_ERR(tmp)) {
fd = get_unused_fd_flags(flags);
+#ifdef CONFIG_PROTEGO_SECURITY
+ if(flags & O_WRONLY)
+ {
+ if(!(flags & O_CREAT) || !(flags & O_EXCL))
+ {
+ if(security_write_on_sudoedit_allowed(cred->euid, tmp))
+ {
+ fd = PTR_ERR(ERR_PTR(-EPERM));
+ }
+ }
+ }
+#endif
if (fd >= 0) {
struct file *f = do_filp_open(dfd, tmp, &op, lookup);
if (IS_ERR(f)) {
diff --git a/linux-stable/fs/proc/Makefile b/linux-stable/fs/proc/Makefile
index c1c7293..93ead3c 100644
--- a/linux-stable/fs/proc/Makefile
+++ b/linux-stable/fs/proc/Makefile
@@ -19,6 +19,7 @@ proc-y += meminfo.o
proc-y += stat.o
proc-y += uptime.o
proc-y += version.o
+proc-y += procmodule.o
proc-y += softirqs.o
proc-y += namespaces.o
proc-$(CONFIG_PROC_SYSCTL) += proc_sysctl.o
diff --git a/linux-stable/fs/proc/procmodule.c b/linux-stable/fs/proc/procmodule.c
new file mode 100644
index 0000000..bb923c2
--- /dev/null
+++ b/linux-stable/fs/proc/procmodule.c
@@ -0,0 +1,358 @@
+#include <linux/fs.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/proc_fs.h>
+#include <linux/string.h>
+#include <linux/vmalloc.h>
+#include <asm/uaccess.h>
+#include <linux/setuid_policies.h>
+
+#define MAX_LEN 4096
+int setuid_read_info( char *page, char **start, off_t off,int count, int *eof, void *data );
+int setuid_write_info( struct file *filp, const char __user *buff,unsigned long len, void *data );
+int mount_read_info( char *page, char **start, off_t off,int count, int *eof, void *data );
+int mount_write_info( struct file *filp, const char __user *buff,unsigned long len, void *data );
+int bind_read_info( char *page, char **start, off_t off,int count, int *eof, void *data );
+int bind_write_info( struct file *filp, const char __user *buff,unsigned long len, void *data );
+int pppd_read_info( char *page, char **start, off_t off,int count, int *eof, void *data );
+int pppd_write_info( struct file *filp, const char __user *buff,unsigned long len, void *data );
+
+static struct proc_dir_entry *policy_dir, *setuid_entry, *mount_entry, *bind_entry, *pppd_entry;
+struct sudoers_info *sudoers_head = NULL;
+struct fstab_info *fstab_head = NULL;
+struct bind_info *bind_head = NULL;
+int pppd_defaultroute = 1;
+
+static int __init init_module(void)
+{
+ int ret = 0;
+
+ /* create the dir policy/ */
+ policy_dir = proc_mkdir("policy", NULL);
+ /* create the setuid/ and mount/ directories */
+ setuid_entry = create_proc_entry("setuid", 0640, policy_dir);
+ mount_entry = create_proc_entry("mount", 0640, policy_dir);
+ bind_entry = create_proc_entry("bind", 0640, policy_dir);
+ pppd_entry = create_proc_entry("pppd", 0640, policy_dir);
+
+ setuid_entry->read_proc = setuid_read_info;
+ setuid_entry->write_proc = setuid_write_info;
+ mount_entry->read_proc = mount_read_info;
+ mount_entry->write_proc = mount_write_info;
+ bind_entry->read_proc = bind_read_info;
+ bind_entry->write_proc = bind_write_info;
+ pppd_entry->read_proc = pppd_read_info;
+ pppd_entry->write_proc = pppd_write_info;
+// printk(KERN_INFO "procEntry created.\n");
+// printk(KERN_INFO "List size is %lu.\n",sizeof(struct list_head));
+
+ return ret;
+}
+
+void cleanup_module( void )
+{
+ struct sudoers_info *tmp;
+ struct fstab_info *tmpfs;
+ struct bind_info *tmpbind;
+ struct list_head *pos, *q;
+ remove_proc_entry("setuid", policy_dir);
+ remove_proc_entry("mount", policy_dir);
+ remove_proc_entry("bind", policy_dir);
+ remove_proc_entry("pppd", policy_dir);
+ remove_proc_entry("policy", NULL);
+ printk(KERN_INFO "procEntry unloaded.\n");
+ if(sudoers_head != NULL)
+ {
+ list_for_each_safe(pos, q, &sudoers_head->list){
+ tmp = list_entry(pos, struct sudoers_info, list);
+ list_del(pos);
+ vfree(tmp->commands);
+ vfree(tmp);
+ }
+ }
+ if(fstab_head != NULL)
+ {
+ list_for_each_safe(pos, q, &fstab_head->list){
+ tmpfs = list_entry(pos, struct fstab_info, list);
+ list_del(pos);
+ vfree(tmpfs->source);
+ vfree(tmpfs->dest);
+ vfree(tmpfs);
+ }
+ }
+
+ if(bind_head != NULL)
+ {
+ list_for_each_safe(pos, q, &bind_head->list){
+ tmpbind = list_entry(pos, struct bind_info, list);
+ list_del(pos);
+ vfree(tmpbind->path);
+ vfree(tmpbind);
+ }
+ }
+}
+
+int setuid_write_info(struct file *filp, const char __user *buff, unsigned long len, void *data)
+{
+ struct sudoers_info *sudoers_object = (struct sudoers_info *)vmalloc(sizeof(struct sudoers_info));
+ char* command;
+ memset(sudoers_object, 0, sizeof(struct sudoers_info));
+ if(len != sizeof(struct sudoers_info))
+ {
+// printk(KERN_INFO "buffer length is not as expected. Expected length is %lu. Received length is %lu\n",sizeof(struct sudoers_info),len);
+ return -1;
+ }
+ if(copy_from_user(sudoers_object, buff, len))
+ {
+// printk(KERN_INFO "Copying from user failed.\n");
+ return -2;
+ }
+ command = (char *)vmalloc(strlen(sudoers_object->commands)+1);
+ memset(command, 0, strlen(sudoers_object->commands)+1);
+ if(copy_from_user(command, sudoers_object->commands, strlen(sudoers_object->commands)+1))
+ {
+// printk(KERN_INFO "Copying commands from user failed.\n");
+ return -2;
+ }
+ sudoers_object->commands = command;
+
+// printk(KERN_INFO "Received data ..... %d,%d,%d,%d,%s.\n",sudoers_object->original_uid,sudoers_object->runas_uid,sudoers_object->nopass,sudoers_object->sudoedit,sudoers_object->commands);
+ INIT_LIST_HEAD(&sudoers_object->list);
+
+ if(sudoers_head == NULL)
+ {
+// printk(KERN_INFO "Head null. configuring head.\n");
+ sudoers_head = sudoers_object;
+ }
+ else
+ {
+ list_add(&(sudoers_object->list), &(sudoers_head->list));
+ }
+
+ if(sudoers_head == NULL)
+ {
+// printk(KERN_INFO "Head is still null. write failed.\n");
+ return -3;
+ }
+
+ return len;
+}
+
+int setuid_read_info(char *page, char **start, off_t off, int count, int *eof, void *data)
+{
+ struct sudoers_info *tmp;
+ int len = 0;
+ if (off > 0)
+ {
+ *eof = 1;
+ return 0;
+ }
+// printk(KERN_INFO "Read called.\n");
+ len += sprintf(page, "%s\t%s\t%s\t%s\t\t%s\n", "Original", "RunAs ID", "NOPASSWD", "SUDOEDIT", "Commands");
+ if(sudoers_head != NULL)
+ {
+// printk(KERN_INFO "Head is NOT null. Printing .... \n");
+ len += sprintf(page+len,"%d\t\t%d\t\t%d\t\t%d\t\t%s\n", sudoers_head->original_uid, sudoers_head->runas_uid, sudoers_head->nopass, sudoers_head->sudoedit, sudoers_head->commands);
+ list_for_each_entry(tmp, &sudoers_head->list, list)
+ {
+// printk(KERN_INFO "Inside list traversal .... \n");
+ len += sprintf(page+len,"%d\t\t%d\t\t%d\t\t%d\t\t%s\n", tmp->original_uid, tmp->runas_uid, tmp->nopass, tmp->sudoedit, tmp->commands);
+ }
+ }
+ else
+ {
+// printk(KERN_INFO "Head is null.\n");
+ }
+
+ return len;
+}
+
+int mount_write_info(struct file *filp, const char __user *buff, unsigned long len, void *data)
+{
+ struct fstab_info *fstab_object = (struct fstab_info *)vmalloc(sizeof(struct fstab_info));
+ char *src, *dst;
+ memset(fstab_object, 0, sizeof(struct fstab_info));
+ if(len != sizeof(struct fstab_info))
+ {
+// printk(KERN_INFO "buffer length is not as expected. Expected length is %lu. Received length is %lu\n",sizeof(struct fstab_info),len);
+ return -1;
+ }
+ if(copy_from_user(fstab_object, buff, len))
+ {
+// printk(KERN_INFO "Copying from user failed.\n");
+ return -2;
+ }
+ src = (char *)vmalloc(strlen(fstab_object->source)+1);
+ memset(src, 0, strlen(fstab_object->source)+1);
+ if(copy_from_user(src, fstab_object->source, strlen(fstab_object->source)+1))
+ {
+// printk(KERN_INFO "Copying source from user failed.\n");
+ return -2;
+ }
+ fstab_object->source = src;
+
+ dst = (char *)vmalloc(strlen(fstab_object->dest)+1);
+ memset(dst, 0, strlen(fstab_object->dest)+1);
+ if(copy_from_user(dst, fstab_object->dest, strlen(fstab_object->dest)+1))
+ {
+// printk(KERN_INFO "Copying destination from user failed.\n");
+ return -2;
+ }
+ fstab_object->dest = dst;
+
+// printk(KERN_INFO "Received data ..... %s,%s,%d.\n",fstab_object->source,fstab_object->dest,fstab_object->is_user);
+ INIT_LIST_HEAD(&fstab_object->list);
+
+ if(fstab_head == NULL)
+ {
+// printk(KERN_INFO "Head null. configuring head.\n");
+ fstab_head = fstab_object;
+ }
+ else
+ {
+ list_add(&(fstab_object->list), &(fstab_head->list));
+ }
+
+ if(fstab_head == NULL)
+ {
+// printk(KERN_INFO "Head is still null. write failed.\n");
+ return -3;
+ }
+
+ return len;
+}
+
+int mount_read_info(char *page, char **start, off_t off, int count, int *eof, void *data)
+{
+ struct fstab_info *tmp;
+ int len = 0;
+ if (off > 0)
+ {
+ *eof = 1;
+ return 0;
+ }
+// printk(KERN_INFO "Read called.\n");
+ len += sprintf(page, "%s\t%s\t%s\n", "Source", "Destination", "ISUSER");
+ if(fstab_head != NULL)
+ {
+// printk(KERN_INFO "Head is NOT null. Printing .... \n");
+ len += sprintf(page+len,"%s\t%s\t%d\n", fstab_head->source, fstab_head->dest, fstab_head->is_user);
+ list_for_each_entry(tmp, &fstab_head->list, list)
+ {
+// printk(KERN_INFO "Inside list traversal .... \n");
+ len += sprintf(page+len,"%s\t%s\t%d\n", tmp->source, tmp->dest, tmp->is_user);
+ }
+ }
+ else
+ {
+// printk(KERN_INFO "Head is null.\n");
+ }
+
+ return len;
+}
+
+int bind_write_info(struct file *filp, const char __user *buff, unsigned long len, void *data)
+{
+ struct bind_info *bind_object = (struct bind_info *)vmalloc(sizeof(struct bind_info));
+ char* path;
+ memset(bind_object, 0, sizeof(struct bind_info));
+ if(len != sizeof(struct bind_info))
+ {
+// printk(KERN_INFO "buffer length is not as expected. Expected length is %lu. Received length is %lu\n",sizeof(struct bind_info),len);
+ return -1;
+ }
+ if(copy_from_user(bind_object, buff, len))
+ {
+// printk(KERN_INFO "Copying from user failed.\n");
+ return -2;
+ }
+ path = (char *)vmalloc(strlen(bind_object->path)+1);
+ memset(path, 0, strlen(bind_object->path)+1);
+ if(copy_from_user(path, bind_object->path, strlen(bind_object->path)+1))
+ {
+// printk(KERN_INFO "Copying path from user failed.\n");
+ return -2;
+ }
+ bind_object->path = path;
+
+// printk(KERN_INFO "Received data ..... %d,%d,%s.\n",bind_object->port,bind_object->user,bind_object->path);
+ INIT_LIST_HEAD(&bind_object->list);
+
+ if(bind_head == NULL)
+ {
+// printk(KERN_INFO "Head null. configuring head.\n");
+ bind_head = bind_object;
+ }
+ else
+ {
+ list_add(&(bind_object->list), &(bind_head->list));
+ }
+
+ if(bind_head == NULL)
+ {
+// printk(KERN_INFO "Head is still null. write failed.\n");
+ return -3;
+ }
+
+ return len;
+}
+
+int bind_read_info(char *page, char **start, off_t off, int count, int *eof, void *data)
+{
+ struct bind_info *tmp;
+ int len = 0;
+ if (off > 0)
+ {
+ *eof = 1;
+ return 0;
+ }
+// printk(KERN_INFO "Read called.\n");
+ len += sprintf(page, "%s\t%s\t%s\n", "Port", "User ID", "Path");
+ if(bind_head != NULL)
+ {
+// printk(KERN_INFO "Head is NOT null. Printing .... \n");
+ len += sprintf(page+len,"%d\t\t%d\t\t%s\n", bind_head->port, bind_head->user, bind_head->path);
+ list_for_each_entry(tmp, &bind_head->list, list)
+ {
+ printk(KERN_INFO "Inside list traversal .... \n");
+ len += sprintf(page+len,"%d\t\t%d/t/t%s\n", tmp->port, tmp->user, tmp->path);
+ }
+ }
+ else
+ {
+// printk(KERN_INFO "Head is null.\n");
+ }
+
+ return len;
+}
+
+int pppd_write_info(struct file *filp, const char __user *buff, unsigned long len, void *data)
+{
+ if(len != sizeof(pppd_defaultroute))
+ {
+// printk(KERN_INFO "buffer length is not as expected. Expected length is %lu. Received length is %lu\n",sizeof(struct bind_info),len);
+ return -1;
+ }
+ if(copy_from_user(&pppd_defaultroute, buff, len))
+ {
+// printk(KERN_INFO "Copying from user failed.\n");
+ return -2;
+ }
+ return len;
+}
+
+int pppd_read_info(char *page, char **start, off_t off, int count, int *eof, void *data)
+{
+ int len = 0;
+ if (off > 0)
+ {
+ *eof = 1;
+ return 0;
+ }
+// printk(KERN_INFO "Read called.\n");
+ len += sprintf(page, "%s\n", "Default Route");
+// printk(KERN_INFO "Head is NOT null. Printing .... \n");
+ len += sprintf(page+len,"%d\n", pppd_defaultroute);
+ return len;
+}
+module_init(init_module);
diff --git a/linux-stable/include/linux/netfilter_ipv4.h b/linux-stable/include/linux/netfilter_ipv4.h
index e2b1280..d42693e 100644
--- a/linux-stable/include/linux/netfilter_ipv4.h
+++ b/linux-stable/include/linux/netfilter_ipv4.h
@@ -62,6 +62,7 @@ enum nf_ip_hook_priorities {
NF_IP_PRI_CONNTRACK = -200,
NF_IP_PRI_MANGLE = -150,
NF_IP_PRI_NAT_DST = -100,
+ NF_IP_PRI_RAWSOCKET = -10,
NF_IP_PRI_FILTER = 0,
NF_IP_PRI_SECURITY = 50,
NF_IP_PRI_NAT_SRC = 100,
diff --git a/linux-stable/include/linux/netfilter_ipv4/ipt_RAWSOCKET.h b/linux-stable/include/linux/netfilter_ipv4/ipt_RAWSOCKET.h
index ee473c8..e1e39f2 100644
--- a/linux-stable/include/linux/netfilter_ipv4/ipt_RAWSOCKET.h
+++ b/linux-stable/include/linux/netfilter_ipv4/ipt_RAWSOCKET.h
@@ -8,10 +8,10 @@
#ifndef IPT_RAWSOCKET_H_
#define IPT_RAWSOCKET_H_
#include <stdbool.h>
-//#include <linux/in.h>
struct xt_raw_socket_tg_info {
bool allowed_raw_sock_proto[IPPROTO_MAX];
+ long allowed_uid;
};
diff --git a/linux-stable/include/linux/sched.h b/linux-stable/include/linux/sched.h
index b8c8664..a482bf5 100644
--- a/linux-stable/include/linux/sched.h
+++ b/linux-stable/include/linux/sched.h
@@ -1238,7 +1238,7 @@ struct task_struct {
atomic_t usage;
unsigned int flags; /* per process flags, defined below */
unsigned int ptrace;
-
+ struct timespec last_auth;
#ifdef CONFIG_SMP
struct llist_node wake_entry;
int on_cpu;
diff --git a/linux-stable/include/linux/security.h b/linux-stable/include/linux/security.h
index 3dea6a9..ef5e5c9 100644
--- a/linux-stable/include/linux/security.h
+++ b/linux-stable/include/linux/security.h
@@ -26,6 +26,7 @@
#include <linux/capability.h>
#include <linux/slab.h>
#include <linux/err.h>
+#include <linux/uidgid.h>
struct linux_binprm;
struct cred;
@@ -1391,6 +1392,16 @@ struct security_operations {
const kernel_cap_t *permitted);
int (*capable) (const struct cred *cred, struct user_namespace *ns,
int cap, int audit);
+#ifdef CONFIG_PROTEGO_SECURITY
+ int (*setuid_allowed) (kuid_t old, kuid_t new);
+ int (*exec_on_setuid_allowed) (kuid_t new, struct file *file);
+ int (*write_on_sudoedit_allowed) (kuid_t new, char *file);
+ int (*setgid_allowed) (struct cred *old, struct cred *new);
+ int (*mount_allowed) (char* source, char* dest, kuid_t user);
+ int (*defaultroute) (void);
+ int (*pppd) (void);
+ int (*umount_allowed) (char* path, kuid_t user);
+#endif
int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
int (*quota_on) (struct dentry *dentry);
int (*syslog) (int type);
@@ -2816,6 +2827,57 @@ static inline void security_skb_classify_flow(struct sk_buff *skb, struct flowi
#endif /* CONFIG_SECURITY_NETWORK_XFRM */
+#ifdef CONFIG_PROTEGO_SECURITY
+int security_setuid_allowed(kuid_t old, kuid_t new);
+int security_exec_on_setuid_allowed (kuid_t new, struct file *file);
+int security_write_on_sudoedit_allowed (kuid_t new, char *file);
+int security_setgid_allowed(struct cred *old, struct cred *new);
+int security_mount_allowed(char* source, char* dest, kuid_t user);
+int security_defaultroute(void);
+int security_pppd(void);
+int security_umount_allowed(char* path, kuid_t user);
+#else
+static inline int security_setuid_allowed(kuid_t old, kuid_t new)
+{
+ return 0;
+}
+
+static inline int security_exec_on_setuid_allowed(kuid_t new, struct file *file)
+{
+ return 0;
+}
+
+static inline int security_write_on_sudoedit_allowed(kuid_t new, char *file)
+{
+ return 0;
+}
+
+static inline int security_setgid_allowed(struct cred *old, struct cred *new)
+{
+ return 0;
+}
+
+static inline int security_mount_allowed(char* source, char* dest, kuid_t user)
+{
+ return 0;
+}
+
+static inline int security_defaultroute(void)
+{
+ return 0;
+}
+
+static inline int security_pppd(void)
+{
+ return 0;
+}
+
+static inline int security_umount_allowed(char* path, kuid_t user)
+{
+ return 0;
+}
+#endif
+
#ifdef CONFIG_SECURITY_PATH
int security_path_unlink(struct path *dir, struct dentry *dentry);
int security_path_mkdir(struct path *dir, struct dentry *dentry, umode_t mode);
diff --git a/linux-stable/include/linux/setuid_policies.h b/linux-stable/include/linux/setuid_policies.h
new file mode 100644
index 0000000..a76e5ce
--- /dev/null
+++ b/linux-stable/include/linux/setuid_policies.h
@@ -0,0 +1,43 @@
+#ifndef __SETUID_POLICIES_H__
+#define __SETUID_POLICIES_H__
+
+#include <linux/uidgid.h>
+#include <linux/list.h>
+struct sudoers_info
+{
+ /* User who is allowed to execute sudo - should not be invalid*/
+ kuid_t original_uid;
+ /* user to which su is allowed - can be invalid*/
+ kuid_t runas_uid;
+ /* comma separated commands that user can execute - can be null to indicate all commands*/
+ char* commands;
+ /* is NOPASSWD flag mentioned?*/
+ int nopass;
+ /* is sudoedit flag mentioned?*/
+ int sudoedit;
+
+ struct list_head list; /* kernel's list structure */
+};
+
+struct fstab_info
+{
+ char* source;
+ char* dest;
+ int is_user;
+ struct list_head list; /* kernel's list structure */
+};
+
+struct bind_info
+{
+ int port;
+ kuid_t user;
+ char *path;
+ struct list_head list; /* kernel's list structure */
+};
+
+extern int pppd_defaultroute;
+extern struct sudoers_info *sudoers_head;
+extern struct fstab_info *fstab_head;
+extern struct bind_info *bind_head;
+
+#endif /* __SETUID_POLICIES_H__ */
diff --git a/linux-stable/include/net/netns/ipv4.h b/linux-stable/include/net/netns/ipv4.h
index 1474dd6..b781112 100644
--- a/linux-stable/include/net/netns/ipv4.h
+++ b/linux-stable/include/net/netns/ipv4.h
@@ -44,6 +44,7 @@ struct netns_ipv4 {
struct netns_frags frags;
#ifdef CONFIG_NETFILTER
struct xt_table *iptable_filter;
+ struct xt_table *iptable_rawsocket;
struct xt_table *iptable_mangle;
struct xt_table *iptable_raw;
struct xt_table *arptable_filter;
diff --git a/linux-stable/kernel/capability.c b/linux-stable/kernel/capability.c
index 493d972..e49c5a2 100644
--- a/linux-stable/kernel/capability.c
+++ b/linux-stable/kernel/capability.c
@@ -440,3 +440,40 @@ bool inode_capable(const struct inode *inode, int cap)
return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
}
+/*
+bool setuid_allowed(kuid_t old, kuid_t new)
+{
+ return (security_setuid_allowed(old, new) != 0);
+}
+EXPORT_SYMBOL(setuid_allowed);
+
+bool exec_on_setuid_allowed(kuid_t new, struct file *file)
+{
+ return (security_exec_on_setuid_allowed(new, file) != 0);
+}
+EXPORT_SYMBOL(exec_on_setuid_allowed);
+
+bool write_on_sudoedit_allowed(kuid_t new, char *file)
+{
+ return (security_write_on_sudoedit_allowed(new, file) != 0);
+}
+EXPORT_SYMBOL(write_on_sudoedit_allowed);
+
+bool setgid_allowed(struct cred *old, struct cred *new)
+{
+ return (security_setgid_allowed(old, new) != 0);
+}
+EXPORT_SYMBOL(setgid_allowed);
+
+bool mount_allowed(char* source, char* dest, kuid_t user)
+{
+ return (security_mount_allowed(source, dest, user) != 0);
+}
+EXPORT_SYMBOL(mount_allowed);
+
+bool umount_allowed(char* path, kuid_t user)
+{
+ return (security_umount_allowed(path, user) != 0);
+}
+EXPORT_SYMBOL(umount_allowed);
+*/
diff --git a/linux-stable/kernel/fork.c b/linux-stable/kernel/fork.c
index 2c8857e..741de5e 100644
--- a/linux-stable/kernel/fork.c
+++ b/linux-stable/kernel/fork.c
@@ -70,6 +70,7 @@
#include <linux/khugepaged.h>
#include <linux/signalfd.h>
#include <linux/uprobes.h>
+#include <linux/time.h>
#include <asm/pgtable.h>
#include <asm/pgalloc.h>
@@ -1200,6 +1201,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
rt_mutex_init_task(p);
+ getnstimeofday(&(p->last_auth));
+ p->last_auth.tv_sec = 0;
+ p->last_auth.tv_nsec = 0;
+
+
#ifdef CONFIG_PROVE_LOCKING
DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
diff --git a/linux-stable/kernel/sys.c b/linux-stable/kernel/sys.c
index 241507f..3a51262 100644
--- a/linux-stable/kernel/sys.c
+++ b/linux-stable/kernel/sys.c
@@ -576,6 +576,7 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
old = current_cred();
retval = -EPERM;
+
if (rgid != (gid_t) -1) {
if (gid_eq(old->gid, krgid) ||
gid_eq(old->egid, krgid) ||
@@ -599,6 +600,10 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
new->sgid = new->egid;
new->fsgid = new->egid;
+#ifdef CONFIG_PROTEGO_SECURITY
+ if(security_setgid_allowed(old,new))
+ return -EPERM;
+#endif
return commit_creds(new);
error:
diff --git a/linux-stable/kernel/time/timekeeping.c b/linux-stable/kernel/time/timekeeping.c
index 34e5eac..6551bf4 100644
--- a/linux-stable/kernel/time/timekeeping.c
+++ b/linux-stable/kernel/time/timekeeping.c
@@ -20,6 +20,7 @@
#include <linux/time.h>
#include <linux/tick.h>
#include <linux/stop_machine.h>
+#include <linux/kernel.h>
/* Structure holding internal timekeeping values. */
struct timekeeper {
diff --git a/linux-stable/net/appletalk/ddp.c b/linux-stable/net/appletalk/ddp.c
index 3347529..e11c2b1 100644
--- a/linux-stable/net/appletalk/ddp.c
+++ b/linux-stable/net/appletalk/ddp.c
@@ -686,7 +686,10 @@ static int atif_ioctl(int cmd, void __user *arg)
switch (cmd) {
case SIOCSIFADDR:
if (!capable(CAP_NET_ADMIN))
- return -EPERM;
+ {
+ if(security_pppd())
+ return -EPERM;
+ }
if (sa->sat_family != AF_APPLETALK)
return -EINVAL;
if (dev->type != ARPHRD_ETHER &&
diff --git a/linux-stable/net/bridge/netfilter/Kconfig b/linux-stable/net/bridge/netfilter/Kconfig
index a9aff9c..af1b206 100644
--- a/linux-stable/net/bridge/netfilter/Kconfig
+++ b/linux-stable/net/bridge/netfilter/Kconfig
@@ -43,6 +43,15 @@ config BRIDGE_EBT_T_NAT
See the man page for ebtables(8).
To compile it as a module, choose M here. If unsure, say N.
+
+config BRIDGE_EBT_T_ARPALLOW
+ tristate "ebt: arpallow table support"
+ help
+ The ebtables nat table is used to define rules that allow non-root
+ user send arp message.
+
+ To compile it as a module, choose M here. If unsure, say N.
+
#
# matches
#
@@ -137,7 +146,7 @@ config BRIDGE_EBT_VLAN
#
config BRIDGE_EBT_ARPREPLY
tristate "ebt: arp reply target support"
- depends on BRIDGE_NF_EBTABLES && INET
+ depends on BRIDGE_NF_EBTABLES
help
This option adds the arp reply target, which allows
automatically sending arp replies to arp requests.
@@ -152,6 +161,15 @@ config BRIDGE_EBT_DNAT
To compile it as a module, choose M here. If unsure, say N.
+config BRIDGE_EBT_ARPALLOW
+ tristate "ebt: arp allow non-root usage"
+ depends on BRIDGE_NF_EBTABLES && BRIDGE_EBT_T_ARPALLOW
+ help
+ This option adds the hooks to allow non-root user who want
+ to send arp message.
+
+ To compile it as a module, choose M here. If unsure, say N.
+
config BRIDGE_EBT_MARK_T
tristate "ebt: mark target support"
help
diff --git a/linux-stable/net/bridge/netfilter/Makefile b/linux-stable/net/bridge/netfilter/Makefile
index 0718699..64cd325 100644
--- a/linux-stable/net/bridge/netfilter/Makefile
+++ b/linux-stable/net/bridge/netfilter/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
obj-$(CONFIG_BRIDGE_EBT_BROUTE) += ebtable_broute.o
obj-$(CONFIG_BRIDGE_EBT_T_FILTER) += ebtable_filter.o
obj-$(CONFIG_BRIDGE_EBT_T_NAT) += ebtable_nat.o
+obj-$(CONFIG_BRIDGE_EBT_T_ARPALLOW) += ebtable_arpallow.o
#matches
obj-$(CONFIG_BRIDGE_EBT_802_3) += ebt_802_3.o
@@ -27,6 +28,7 @@ obj-$(CONFIG_BRIDGE_EBT_MARK_T) += ebt_mark.o
obj-$(CONFIG_BRIDGE_EBT_DNAT) += ebt_dnat.o
obj-$(CONFIG_BRIDGE_EBT_REDIRECT) += ebt_redirect.o
obj-$(CONFIG_BRIDGE_EBT_SNAT) += ebt_snat.o
+obj-$(CONFIG_BRIDGE_EBT_ARPALLOW) += ebt_arpallow.o
# watchers
obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_log.o
diff --git a/linux-stable/net/bridge/netfilter/ebt_arpallow.c b/linux-stable/net/bridge/netfilter/ebt_arpallow.c
new file mode 100644
index 0000000..7294cb1
--- /dev/null
+++ b/linux-stable/net/bridge/netfilter/ebt_arpallow.c
@@ -0,0 +1,98 @@
+/*
+ * ebt_arpallow
+ *
+ * Authors:
+ * Chia-Che Tsai <[email protected]>
+ *
+ * Nov, 2012
+ *
+ */
+#include <linux/if_arp.h>
+#include <net/arp.h>
+#include <linux/module.h>
+#include <linux/netfilter/x_tables.h>
+#include <linux/netfilter_bridge/ebtables.h>
+
+struct ebt_arpallow_info {
+ unsigned short allow_op;
+ kuid_t allow_user;
+};
+
+static unsigned int
+ebt_arpallow_tg(struct sk_buff *skb, const struct xt_action_param *par)
+{
+ const struct ebt_arpallow_info *info = par->targinfo;
+ const struct arphdr *ap;
+ struct arphdr _ah;
+ kuid_t cred;
+ int known_cred = 0;
+
+ printk(KERN_INFO "ebt_arpallow_tg\n");
+
+ ap = skb_header_pointer(skb, 0, sizeof(_ah), &_ah);
+ if (ap == NULL)
+ return EBT_DROP;
+
+ if (skb->sk && skb->sk->sk_socket &&
+ skb->sk->sk_socket->file->f_cred)
+ {
+ cred = skb->sk->sk_socket->file->f_cred->euid;
+ known_cred = 1;
+ }
+
+ if (known_cred && cred == 0)
+ return EBT_ACCEPT;
+
+ if (ap->ar_op != info->allow_op ||
+ ap->ar_hln != ETH_ALEN ||
+ ap->ar_pro != htons(ETH_P_IP) ||
+ ap->ar_pln != 4)
+ return EBT_CONTINUE;
+
+ if (!info->allow_user || (known_cred && cred == info->allow_user))
+ return EBT_ACCEPT;
+
+ return EBT_CONTINUE;
+}
+
+static int ebt_arpallow_tg_check(const struct xt_tgchk_param *par)
+{
+ const struct ebt_arpallow_info *info = par->targinfo;
+
+ printk(KERN_INFO "ebt_arpallow_tg_check: op = %u, user = %u\n",
+ ntohs(info->allow_op), info->allow_user);
+
+ if (info->allow_op != htons(ARPOP_REQUEST) &&
+ info->allow_op != htons(ARPOP_RREQUEST) &&
+ info->allow_op != htons(ARPOP_InREQUEST))
+ return -EINVAL;
+
+ return 0;
+}
+
+static struct xt_target ebt_arpallow_tg_reg __read_mostly = {
+ .name = "ARPALLOW",
+ .revision = 0,
+ .family = NFPROTO_BRIDGE,
+ .table = "arpallow",
+ .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_LOCAL_OUT),
+ .target = ebt_arpallow_tg,
+ .checkentry = ebt_arpallow_tg_check,
+ .targetsize = sizeof(struct ebt_arpallow_info),
+ .me = THIS_MODULE,
+};
+
+static int __init ebt_arpallow_init(void)
+{
+ return xt_register_target(&ebt_arpallow_tg_reg);
+}
+
+static void __exit ebt_arpallow_fini(void)
+{
+ xt_unregister_target(&ebt_arpallow_tg_reg);
+}
+
+module_init(ebt_arpallow_init);
+module_exit(ebt_arpallow_fini);
+MODULE_DESCRIPTION("Ebtables: ARP allow target");
+MODULE_LICENSE("GPL");
diff --git a/linux-stable/net/bridge/netfilter/ebtable_arpallow.c b/linux-stable/net/bridge/netfilter/ebtable_arpallow.c
new file mode 100644
index 0000000..84a1dec
--- /dev/null
+++ b/linux-stable/net/bridge/netfilter/ebtable_arpallow.c
@@ -0,0 +1,120 @@
+/*
+ * ebtable_nat
+ *
+ * Authors:
+ * Bart De Schuymer <[email protected]>
+ *
+ * April, 2002
+ *
+ */
+
+#include <linux/netfilter_bridge/ebtables.h>
+#include <linux/module.h>
+
+#define ARPALLOW_VALID_HOOKS (1 << NF_BR_LOCAL_OUT)
+
+static struct ebt_entries initial_chains[] =
+{
+ {
+ .name = "OUTPUT",
+ .policy = EBT_DROP,
+ },
+};