Skip to contentSkip to conversation

+ clocksource-add-verification-watchdog-helper-fix-3.patch added to -mm tree

PATCH In review [email protected] 8 participants 36 messages Jan 28, 2007 – Feb 9, 2007 7 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

[email protected]

author tree notice
#0 lore raw

The patch titled
clocksource-add-verification-watchdog-helper fix 3
has been added to the -mm tree. Its filename is
clocksource-add-verification-watchdog-helper-fix-3.patch

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this

------------------------------------------------------
Subject: clocksource-add-verification-watchdog-helper fix 3
From: Andrew Morton <[email protected]>

Try to make this patch series bisectable

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>

---

 kernel/time/clocksource.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff -puN include/linux/clocksource.h~clocksource-add-verification-watchdog-helper-fix-3 include/linux/clocksource.h

kernel/time/clocksource.c renamed from kernel/time/clocksource.c~clocksource-add-verification-watchdog-helper-fix-3 +1 -2
diff -puN kernel/time/clocksource.c~clocksource-add-verification-watchdog-helper-fix-3 kernel/time/clocksource.c
@@ -28,7 +28,6 @@
 #include <linux/sysdev.h>
 #include <linux/init.h>
 #include <linux/module.h>
-#include <linux/tick.h>
 
 /* XXX - Would like a better way for initializing curr_clocksource */
 extern struct clocksource clocksource_jiffies;
@@ -115,7 +114,7 @@ static void clocksource_watchdog(unsigne
 				 * system as well so that we transition
 				 * into high-res mode:
 				 */
-				tick_clock_notify();
+//				tick_clock_notify();
 			}
 			cs->flags |= CLOCK_SOURCE_WATCHDOG;
 			cs->wd_last = csnow;

_

Patches currently in -mm which might be from [email protected] are

origin.patch
x86-fix-vdso-mapping-for-aout-executables-fixes.patch x86-fix-vdso-mapping-for-aout-executables-fixes-2.patch x86-fix-vdso-mapping-for-aout-executables-cleanups.patch x86-fix-vdso-mapping-for-aout-executables-doh.patch mm-show-bounce-pages-in-oom-killer-output.patch use-correct-macros-in-raid-code-not-raw-asm-include.patch macintosh-mangle-caps-lock-events-on-adb-keyboards.patch
git-acpi.patch exit-acpi-processor-module-gracefully-if-acpi-is-disabled-tidy.patch sony_apci-resume.patch
sony_apci-resume-fix.patch video-sysfs-support-take-2-add-dev-argument-for-backlight_device_register-sony_acpi-fix.patch git-alsa.patch
agpgart-allow-drm-populated-agp-memory-types-tidy.patch rewrite-lock-in-cpufreq-to-eliminate-cpufreq-hotplug-related-issues-fix-2.patch powerpc-make-it-compile.patch
git-dvb.patch
dvb-video_buf-depends-on-pci.patch
git-gfs2-nmw.patch
ia64-enable-config_debug_spinlock_sleep.patch
git-ieee1394.patch
git-input.patch
git-libata-all.patch
pata_platform-set_mode-fix.patch sata_nv-cleanup-adma-error-handling-v2-cleanup.patch mm-ide-ide-acpi-support-warning-fix.patch
git-lxdialog-fixup.patch
git-mips-kconfig-fix.patch
git-mips-prom_free_prom_memory-borkage.patch
git-mmc.patch
git-mmc-fixup.patch
git-ubi.patch
git-netdev-all.patch
git-netdev-all-fixup.patch
git-netdev-all-atl1-build-fix.patch
git-netdev-all-atl1-pm-fix.patch
82596-warning-fix.patch update-smc91x-driver-with-arm-versatile-board-info.patch drivers-net-ns83820c-add-paramter-to-disable-auto.patch bonding-replace-kmalloc-memset-pairs-with-the-appropriate-kzalloc-calls-fix.patch dccp-warning-fixes.patch
net-uninline-skb_put.patch
ioat-warning-fix.patch
nfs-fix-congestion-control-v4-tweaks.patch
r8169-warning-fixes.patch make-cardbus_mem_size-and-cardbus_io_size-boot-options-fix.patch sh-add-kconfig-default.patch drivers-scsi-mca_53c9xc-save_flags-cli-removal.patch scsi-cover-up-bugs-fix-up-compiler-warnings-in-megaraid-driver.patch git-block-fixup.patch
git-block-borkage.patch
git-block-atomicity-fix.patch fix-gregkh-usb-usbcore-remove-unused-bandwith-related-code.patch nokia-e70-is-an-unusual-device.patch
revert-x86_64-mm-msr-on-cpu.patch spin_lock_irq-enable-interrupts-while-spinning-i386-implementation-fix.patch spin_lock_irq-enable-interrupts-while-spinning-i386-implementation-fix-fix.patch arch-i386-kernel-alternativec-dont-include-bugsh.patch touchkit-ps-2-touchscreen-driver.patch
lumpy-reclaim-v2-page_to_pfn-fix.patch
lumpy-reclaim-v2-tidy.patch avoid-excessive-sorting-of-early_node_map-tidy.patch proc-zoneinfo-fix-vm-stats-display.patch use-zvc-for-inactive-and-active-counts-up-fix.patch
drop-free_pages-fix.patch
drop-free_pages-sparc64-fix.patch get_dirty_limits-accurately-calculate-the-available-memory-that-can-be-dirtied-fix.patch optional-zone_dma-in-the-vm-tidy.patch swsusp-change-code-ordering-in-userc-sanity.patch m68k-uaccessh-needs-schedh.patch
deprecate-smbfs-in-favour-of-cifs.patch drivers-add-lcd-support-3-Kconfig-fix.patch drivers-add-lcd-support-workqueue-fixups.patch add-retain_initrd-boot-option-tweak.patch
count_vm_events-warning-fix.patch procfs-fix-race-between-proc_readdir-and-remove_proc_entry-fix.patch consolidate-line-discipline-number-definitions-v2-sparc-fix.patch consolidate-line-discipline-number-definitions-v2-fix-2.patch add-taint_user-and-ability-to-set-taint-flags-from-userspace-fix-2.patch remove-invalidate_inode_pages.patch add-an-rcu-version-of-list-splicing-fix.patch factor-outstanding-i-o-error-handling-tidy.patch sync_sb_inodes-propagate-errors.patch block_write_full_page-handle-enospc.patch
sysctl-warning-fix.patch
proc_misc-warning-fix.patch
rtc-framework-driver-for-cmos-rtcs-fix.patch rtc-framework-driver-for-cmos-rtcs-fix-2.patch return-enoent-from-ext3_link-when-racing-with-unlink-fix.patch spi-controller-driver-for-omap-microwire-tidy.patch spi-controller-driver-for-omap-microwire-update-fix.patch mips-convert-to-use-shared-apm-emulation-fix.patch
vmi-versus-hrtimers.patch add-a-functions-to-handle-interrupt-affinity-setting-alpha-fix.patch i386-use-gtod-persistent-clock-support.patch clocksource-add-verification-watchdog-helper-fix-2.patch clocksource-add-verification-watchdog-helper-fix-3.patch hrtimers-namespace-and-enum-cleanup-vs-git-input.patch hrtimers-cleanup-locking.patch
hrtimers-add-state-tracking.patch tick-management-dyntick--highres-functionality-fix.patch clockevents-i383-drivers.patch
hrt-dynticks-hotplug-fix-fix.patch generic-vsyscall-gtod-support-for-generic_time-tidy.patch revert-x86_64-mm-ignore-long-smi-interrupts-in-clock-calibration.patch time-x86_64-split-x86_64-kernel-timec-up-tidy.patch time-x86_64-split-x86_64-kernel-timec-up-fix.patch reapply-x86_64-mm-ignore-long-smi-interrupts-in-clock-calibration.patch time-x86_64-convert-x86_64-to-use-generic_time-fix.patch time-x86_64-convert-x86_64-to-use-generic_time-tidy.patch time-x86_64-re-enable-vsyscall-support-for-x86_64-tidy.patch schedule_on_each_cpu-use-preempt_disable.patch implement-flush_work-sanity.patch
implement-flush_work_keventd.patch flush_workqueue-use-preempt_disable-to-hold-off-cpu-hotplug.patch aio-use-flush_work.patch
kblockd-use-flush_work.patch
relayfs-use-flush_keventd_work.patch
tg3-use-flush_keventd_work.patch
e1000-use-flush_keventd_work.patch
libata-use-flush_work.patch
phy-use-flush_work.patch extend-notifier_call_chain-to-count-nr_calls-made.patch extend-notifier_call_chain-to-count-nr_calls-made-fixes-2.patch define-and-use-new-eventscpu_lock_acquire-and-cpu_lock_release-fix.patch eliminate-lock_cpu_hotplug-in-kernel-schedc-fix.patch move-page-writeback-acounting-out-of-macros.patch per-backing_dev-dirty-and-writeback-page-accounting.patch ext2-reservations.patch edac-new-opteron-athlon64-memory-controller-driver.patch omap-gpio-wrappers-tidy.patch
at91-gpio-wrappers-tidy.patch ecryptfs-public-key-packet-management-slab-fix.patch ecryptfs-generalize-metadata-read-write-fix.patch fsaio-add-a-wait-queue-arg-to-the-wait_bit-action-routine-gfs2-fix.patch fsaio-enable-wait-bit-based-filtered-wakeups-to-work-for-aio-fix.patch aio-is-unlikely.patch
sched2-sched-domain-sysctl-use-ctl_unnumbered.patch mm-implement-swap-prefetching-use-ctl_unnumbered.patch swap_prefetch-vs-zoned-counters.patch add-include-linux-freezerh-and-move-definitions-from-prefetch.patch introduce-and-use-get_task_mnt_ns-tweaks.patch user-ns-implement-user-ns-unshare-tidy.patch ipc-namespace-remove-config_ipc_ns-linkage-fix.patch ipc-namespace-remove-config_ipc_ns-linkage-fix-fix.patch dynamic-kernel-command-line-ia64-fix.patch
rcu-preemptible-rcu-fix.patch
readahead-kconfig-options-fix.patch
readahead-minmax_ra_pages.patch
readahead-sysctl-parameters.patch readahead-sysctl-parameters-use-ctl_unnumbered.patch readahead-context-based-method-locking-fix.patch readahead-context-based-method-locking-fix-2.patch readahead-call-scheme-ifdef-fix.patch
readahead-call-scheme-build-fix.patch
readahead-nfsd-case-fix.patch make-copy_from_user_inatomic-not-zero-the-tail-on-i386-vs-reiser4.patch resier4-add-include-linux-freezerh-and-move-definitions-from.patch make-kmem_cache_destroy-return-void-reiser4.patch reiser4-hardirq-include-fix.patch reiser4-run-truncate_inode_pages-in-reiser4_delete_inode.patch reiser4-get_sb_dev-fix.patch
reiser4-vs-zoned-allocator.patch
reiser4-temp-fix.patch
reiser4-kmem_cache_t-removal.patch
reiser4-test_clear_page_dirty.patch
reiser4-vs-git-block.patch
reiser4-vs-git-block-2.patch cyber2010-framebuffer-on-arm-netwinder-fix-tidy.patch statistics-infrastructure-fix-buffer-overflow-in-histogram-with-linear-tidy.patch slim-main-include-fix.patch
mark-struct-file_operations-const-2-fix.patch mark-struct-file_operations-const-4-fix.patch scheduled-removal-of-sa_xxx-interrupt-flags-ata-fix.patch sysctl-c99-convert-ctl_tables-in-ntfs-and-remove-sys_sysctl-support-fix.patch sysctl-create-sys-fs-binfmt_misc-as-an-ordinary-sysctl-entry-warning-fix.patch sysctl-factor-out-sysctl_head_next-from-do_sysctl-warning-fix.patch sysctl-reimplement-the-sysctl-proc-support-warning-fix.patch sysctl-reimplement-the-sysctl-proc-support-fix-2.patch sysctl-remove-the-proc_dir_entry-member-for-the-sysctl-tables-hack.patch sysctl-remove-the-proc_dir_entry-member-for-the-sysctl-tables-ntfs-fix.patch nr_blockdev_pages-in_interrupt-warning.patch
device-suspend-debug.patch
mutex-subsystem-synchro-test-module-fix.patch
slab-leaks3-default-y.patch
vdso-print-fatal-signals-use-ctl_unnumbered.patch restore-rogue-readahead-printk.patch
put_bh-debug.patch
e1000-printk-warning-fixes.patch
acpi_format_exception-debug.patch add-debugging-aid-for-memory-initialisation-problems-fix.patch kmap_atomic-debugging.patch
shrink_slab-handle-bad-shrinkers.patch
squash-ipc-warnings.patch
squash-udf-warnings.patch

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

PATCH 1/1 sysctl selinux: Don't look at table->de

With the sysctl cleanups sysctl is not really a part of proc it just shows up there, and any path based approach will not adequately describe the data as sysctl is essentially a union mount underneath the covers. As designed this mechanism is viewer dependent so trying to be path based gets even worse.

However the permissions in sys_sysctl are currently immutable and going through proc does not change the permission checks when accessing sysctl. So we might as well stick with the well defined sysctl sid, as that is what selinux uses when proc is not compiled in.

I.e. I see no hope for salvaging the selinux_proc_get_sid call in selinux_sysctl so I'm removing it.

---
 security/selinux/hooks.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
security/selinux/hooks.c +2 -6
index 7b38372..3a36057 100644
@@ -1438,12 +1438,8 @@ static int selinux_sysctl(ctl_table *table, int op)
 
 	tsec = current->security;
 
-	rc = selinux_proc_get_sid(table->de, (op == 001) ?
-	                          SECCLASS_DIR : SECCLASS_FILE, &tsid);
-	if (rc) {
-		/* Default to the well-defined sysctl SID. */
-		tsid = SECINITSID_SYSCTL;
-	}
+	/* Use the well-defined sysctl SID. */
+	tsid = SECINITSID_SYSCTL;
 
 	/* The op values are "defined" in sysctl.c, thereby creating
 	 * a bad coupling between this module and sysctl.c */
Signature · 1 line
1.4.4.1.g278f
#9 lore raw

Re: [PATCH] sysctl selinux: Don't look at table->de

Quoted 29 lines · Eric W. Biederman

With the sysctl cleanups sysctl is not really a part of proc it just shows up there, and any path based approach will not adequately describe the data as sysctl is essentially a union mount underneath the covers. As designed this mechanism is viewer dependent so trying to be path based gets even worse.

However the permissions in sys_sysctl are currently immutable and going through proc does not change the permission checks when accessing sysctl. So we might as well stick with the well defined sysctl sid, as that is what selinux uses when proc is not compiled in.

I.e. I see no hope for salvaging the selinux_proc_get_sid call in selinux_sysctl so I'm removing it.

---
 security/selinux/hooks.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
security/selinux/hooks.c +0 -1
index 7b38372..3a36057 100644
@@ -1438,12 +1438,8 @@ static int selinux_sysctl(ctl_table *table, int op)
 
 	tsec = current->security;
 
-	rc = selinux_proc_get_sid(table->de, (op == 001) ?

security/selinux/hooks.c static int selinux_sysctl(ctl_table *table, int op) · line 1445

Quoted 10 lines
security/selinux/hooks.c +2 -5
-	                          SECCLASS_DIR : SECCLASS_FILE, &tsid);
-	if (rc) {
-		/* Default to the well-defined sysctl SID. */
-		tsid = SECINITSID_SYSCTL;
-	}
+	/* Use the well-defined sysctl SID. */
+	tsid = SECINITSID_SYSCTL;
 
 	/* The op values are "defined" in sysctl.c, thereby creating
 	 * a bad coupling between this module and sysctl.c */

NAK. Mapping all sysctls to a single security label prevents any kind of fine-grained security on sysctls, and current policies already make use of the current distinctions to limit access to particular sets of sysctls to particular processes. As is, I'd expect breakage of current systems running SELinux from this patch, because (confined) processes that formerly only required access to specific sysctl labels will suddenly run into denials on the generic fallback label.

If the ctl_table supplied more information about the functional purpose and the security sensitivity of the sysctl, then we could leverage that information instead, as long as we can at least derive the current labelings from that information for compatibility.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#10 lore raw

Re: [PATCH] sysctl selinux: Don't look at table->de

Quoted 7 lines · Stephen Smalley

NAK. Mapping all sysctls to a single security label prevents any kind of fine-grained security on sysctls, and current policies already make use of the current distinctions to limit access to particular sets of sysctls to particular processes. As is, I'd expect breakage of current systems running SELinux from this patch, because (confined) processes that formerly only required access to specific sysctl labels will suddenly run into denials on the generic fallback label.

Agreed, 100% NACK.

Please don't just simply remove long-researched & analyzed MAC security which has been in the kernel for years, which is being used in the field for high assurance systems, because you neglected to consider it during a code cleanup.

- James

Signature · 7 lines
James Morris
<[email protected]>

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#11 lore raw

Re: [PATCH] sysctl selinux: Don't look at table->de

Quoted 10 lines · James Morris
Quoted 7 lines · Stephen Smalley

NAK. Mapping all sysctls to a single security label prevents any kind of fine-grained security on sysctls, and current policies already make use of the current distinctions to limit access to particular sets of sysctls to particular processes. As is, I'd expect breakage of current systems running SELinux from this patch, because (confined) processes that formerly only required access to specific sysctl labels will suddenly run into denials on the generic fallback label.

Quoted 6 lines

Agreed, 100% NACK.

Please don't just simply remove long-researched & analyzed MAC security which has been in the kernel for years, which is being used in the field for high assurance systems, because you neglected to consider it during a code cleanup.

Please don't shoot the messenger when a weakness is found in your code. Systems that increase security without worry that their implementation is correct do not impress me, but I do understand that security has little to do with correctness and everything to do with making it _expensive_ for the other guy to do what he isn't supposed to.

This code path was always in the selinux code for when /proc was compiled out. I could see no way to preserve it so I removed it.

Not knowing if it was a problem, or if we needed to do something more I copied the people who did, at the first available opportunity. Before this code makes it's way into peoples production systems.

Of course after all of the rants against path based security I was amazed to find a code path that was using exactly that in selinux. Equally I'm amazed that all of that long-researched and analysis of the MAC security has not found these issues where you integrate with the rest of the linux kernel.

I'm trying to make things correct, and simple and will be happy to work with you in a way to achieve what you need in a way that does not conflict with the rest of the kernel.

Eric

#12 lore raw

Re: [PATCH] sysctl selinux: Don't look at table->de

Quoted 12 lines · Eric W. Biederman
Quoted 10 lines · James Morris
Quoted 7 lines · Stephen Smalley

NAK. Mapping all sysctls to a single security label prevents any kind of fine-grained security on sysctls, and current policies already make use of the current distinctions to limit access to particular sets of sysctls to particular processes. As is, I'd expect breakage of current systems running SELinux from this patch, because (confined) processes that formerly only required access to specific sysctl labels will suddenly run into denials on the generic fallback label.

Quoted 8 lines
Quoted 6 lines

Agreed, 100% NACK.

Please don't just simply remove long-researched & analyzed MAC security which has been in the kernel for years, which is being used in the field for high assurance systems, because you neglected to consider it during a code cleanup.

Please don't shoot the messenger when a weakness is found in your code.

I'm not sure how breaking our code with your set of patches qualifies as finding a weakness. I will agree that the current handling of sysctl in selinux is fragile and can be improved, but it did work (prior to your patches).

Quoted 4 lines

Systems that increase security without worry that their implementation is correct do not impress me, but I do understand that security has little to do with correctness and everything to do with making it _expensive_ for the other guy to do what he isn't supposed to.

I think you misunderstand; we are concerned about the correctness of our implementation. I think that possibly you are misunderstanding one of the SELinux FAQ answers outside of its historical context (the initial release of a proof-of-concept implementation of flexible MAC in Dec 2000).

Quoted 7 lines

This code path was always in the selinux code for when /proc was compiled out. I could see no way to preserve it so I removed it.

Not knowing if it was a problem, or if we needed to do something more I copied the people who did, at the first available opportunity. Before this code makes it's way into peoples production systems.

Which we appreciate, although it would be nice if you tried building with selinux (and ideally testing with it) in the first place.

Quoted 2 lines

Of course after all of the rants against path based security I was amazed to find a code path that was using exactly that in selinux.

To clarify, in this case, the pathname (relative to the root of proc) is derived from the proc_dir_entry hierarchy and is thus not ambiguous or mutable by userspace, unlike the pathname-based approaches that we have criticized. There is a difference. But we are open to improving the approach via explicit marking of the ctl_table entries with sufficient information.

Quoted 3 lines

I'm trying to make things correct, and simple and will be happy to work with you in a way to achieve what you need in a way that does not conflict with the rest of the kernel.

Good.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#13 lore raw

Re: [PATCH] sysctl selinux: Don't look at table->de

In reply to Stephen Smalley
Quoted 38 lines · Stephen Smalley
Quoted 37 lines · Eric W. Biederman

With the sysctl cleanups sysctl is not really a part of proc it just shows up there, and any path based approach will not adequately describe the data as sysctl is essentially a union mount underneath the covers. As designed this mechanism is viewer dependent so trying to be path based gets even worse.

However the permissions in sys_sysctl are currently immutable and going through proc does not change the permission checks when accessing sysctl. So we might as well stick with the well defined sysctl sid, as that is what selinux uses when proc is not compiled in.

I.e. I see no hope for salvaging the selinux_proc_get_sid call in selinux_sysctl so I'm removing it.

---
 security/selinux/hooks.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
security/selinux/hooks.c +2 -6
index 7b38372..3a36057 100644
@@ -1438,12 +1438,8 @@ static int selinux_sysctl(ctl_table *table, int op)
 
 	tsec = current->security;
 
-	rc = selinux_proc_get_sid(table->de, (op == 001) ?
-	                          SECCLASS_DIR : SECCLASS_FILE, &tsid);
-	if (rc) {
-		/* Default to the well-defined sysctl SID. */
-		tsid = SECINITSID_SYSCTL;
-	}
+	/* Use the well-defined sysctl SID. */
+	tsid = SECINITSID_SYSCTL;
 
Quoted 10 lines

security/selinux/hooks.c static int selinux_sysctl(ctl_table *table, int op) · line 1445

Quoted 2 lines
security/selinux/hooks.c +0 -0
 	/* The op values are "defined" in sysctl.c, thereby creating
 	 * a bad coupling between this module and sysctl.c */

NAK. Mapping all sysctls to a single security label prevents any kind of fine-grained security on sysctls, and current policies already make use of the current distinctions to limit access to particular sets of sysctls to particular processes. As is, I'd expect breakage of current systems running SELinux from this patch, because (confined) processes that formerly only required access to specific sysctl labels will suddenly run into denials on the generic fallback label.

Reasonable. There is the issue that your code already had this code path for when /proc was compiled out.

Quoted 4 lines

If the ctl_table supplied more information about the functional purpose and the security sensitivity of the sysctl, then we could leverage that information instead, as long as we can at least derive the current labelings from that information for compatibility.

What do information do you need to do need? Do you need extra fields in sysctl? I am more than willing to help but I am not familiar enough with selinux to do a reasonable job on my own.

Eric

#14 lore raw

Re: [PATCH] sysctl selinux: Don't look at table->de

Quoted 51 lines · Eric W. Biederman
Quoted 38 lines · Stephen Smalley
Quoted 37 lines · Eric W. Biederman

With the sysctl cleanups sysctl is not really a part of proc it just shows up there, and any path based approach will not adequately describe the data as sysctl is essentially a union mount underneath the covers. As designed this mechanism is viewer dependent so trying to be path based gets even worse.

However the permissions in sys_sysctl are currently immutable and going through proc does not change the permission checks when accessing sysctl. So we might as well stick with the well defined sysctl sid, as that is what selinux uses when proc is not compiled in.

I.e. I see no hope for salvaging the selinux_proc_get_sid call in selinux_sysctl so I'm removing it.

---
 security/selinux/hooks.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
security/selinux/hooks.c +2 -6
index 7b38372..3a36057 100644
@@ -1438,12 +1438,8 @@ static int selinux_sysctl(ctl_table *table, int op)
 
 	tsec = current->security;
 
-	rc = selinux_proc_get_sid(table->de, (op == 001) ?
-	                          SECCLASS_DIR : SECCLASS_FILE, &tsid);
-	if (rc) {
-		/* Default to the well-defined sysctl SID. */
-		tsid = SECINITSID_SYSCTL;
-	}
+	/* Use the well-defined sysctl SID. */
+	tsid = SECINITSID_SYSCTL;
 
Quoted 10 lines

security/selinux/hooks.c static int selinux_sysctl(ctl_table *table, int op) · line 1445

Quoted 2 lines
security/selinux/hooks.c +0 -0
 	/* The op values are "defined" in sysctl.c, thereby creating
 	 * a bad coupling between this module and sysctl.c */

NAK. Mapping all sysctls to a single security label prevents any kind of fine-grained security on sysctls, and current policies already make use of the current distinctions to limit access to particular sets of sysctls to particular processes. As is, I'd expect breakage of current systems running SELinux from this patch, because (confined) processes that formerly only required access to specific sysctl labels will suddenly run into denials on the generic fallback label.

Quoted 2 lines

Reasonable. There is the issue that your code already had this code path for when /proc was compiled out.

True, but a system that disables proc is likely a system with a custom policy anyway, and dependency on proc is fairly basic to selinux these days (due to reliance on /proc/self/attr for process attribute manipulation in place of the old selinux syscalls). Possibly we should just make selinux depend on proc and drop the #ifdef there.

Quoted 8 lines
Quoted 4 lines

If the ctl_table supplied more information about the functional purpose and the security sensitivity of the sysctl, then we could leverage that information instead, as long as we can at least derive the current labelings from that information for compatibility.

What do information do you need to do need? Do you need extra fields in sysctl? I am more than willing to help but I am not familiar enough with selinux to do a reasonable job on my own.

At present, we map the sysctls into functional groups (e.g. net, vm, fs, ...) that parallel the sysctl hierarchy so that we can limit access to only those programs/processes that need access for their purpose, and further partition where it makes sense to do so. We also separate out particularly security sensitive ones like modprobe and hotplug. So if the ctl_table carried some indication of functional grouping and security relevance (for some relatively small number of equivalence classes), then we could map those to labels instead of the current scheme. And if we could have the ctl_table inherit the information from its logical "parent" in the hierarchy by default, then it shouldn't require too invasive a patch.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#15 lore raw

Re: [PATCH] sysctl selinux: Don't look at table->de

Quoted 10 lines · --- Stephen Smalley

True, but a system that disables proc is likely a system with a custom
policy anyway, and dependency on proc is fairly basic to selinux these
days (due to reliance on /proc/self/attr for process attribute
manipulation in place of the old selinux syscalls). Possibly we should
just make selinux depend on proc and drop the #ifdef there.

Alternativly you could move the SELinux specific bits out of /proc/self/attr into an equivalent /selinux/self/attr and avoid that /proc dependency.

Casey Schaufler
[email protected]

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#16 lore raw

Re: [PATCH] sysctl selinux: Don't look at table->de

Quoted 13 lines · Casey Schaufler
Quoted 10 lines · --- Stephen Smalley

True, but a system that disables proc is likely a system with a custom
policy anyway, and dependency on proc is fairly basic to selinux these
days (due to reliance on /proc/self/attr for process attribute
manipulation in place of the old selinux syscalls). Possibly we should
just make selinux depend on proc and drop the #ifdef there.

Quoted 3 lines

Alternativly you could move the SELinux specific bits out of /proc/self/attr into an equivalent /selinux/self/attr and avoid that /proc dependency.

We could, but I don't see any compelling reason to do so. We were specifically told to use proc for the selinux process attributes when we refactored the selinux api for 2.6 inclusion, as they are per-process state and fit naturally into proc.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#17 lore raw

Re: [PATCH] sysctl selinux: Don't look at table->de

In reply to Casey Schaufler
Quoted 3 lines · Casey Schaufler

Alternativly you could move the SELinux specific bits out of /proc/self/attr into an equivalent /selinux/self/attr and avoid that /proc dependency.

Why? procfs is essential for any kind of fullblown linux system, and the selinux actually fits into the original procfs intention, unlike all the other junk we've added over the years.

#18 lore raw

Re: [PATCH] sysctl selinux: Don't look at table->de

Quoted 8 lines · --- Christoph Hellwig
Quoted 3 lines · Casey Schaufler

Alternativly you could move the SELinux specific
bits out of /proc/self/attr into an equivalent
/selinux/self/attr and avoid that /proc

dependency.

Why?

To avoid the dependency and remove the issue.
Just a thought. Weigh the advantages and
disadvantages and do what seems right.

Quoted 2 lines

procfs is essential for any kind of fullblown
linux system,

Kids!

Quoted 2 lines

and the selinux actually fits into the original
procfs intention,

Yes, it does. It's a good use of /proc.

Quoted 2 lines

unlike all the other junk we've added over the
years.

You won't get any arguements from me there.

Casey Schaufler
[email protected]

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#19 lore raw

Re: [PATCH] sysctl selinux: Don't look at table->de

In reply to Stephen Smalley
Quoted 10 lines · Stephen Smalley
Quoted 6 lines
Quoted 4 lines

If the ctl_table supplied more information about the functional purpose and the security sensitivity of the sysctl, then we could leverage that information instead, as long as we can at least derive the current labelings from that information for compatibility.

What do information do you need to do need? Do you need extra fields in

sysctl?

Quoted 2 lines

I am more than willing to help but I am not familiar enough with selinux to do a reasonable job on my own.

Quoted 11 lines

At present, we map the sysctls into functional groups (e.g. net, vm, fs, ...) that parallel the sysctl hierarchy so that we can limit access to only those programs/processes that need access for their purpose, and further partition where it makes sense to do so. We also separate out particularly security sensitive ones like modprobe and hotplug. So if the ctl_table carried some indication of functional grouping and security relevance (for some relatively small number of equivalence classes), then we could map those to labels instead of the current scheme. And if we could have the ctl_table inherit the information from its logical "parent" in the hierarchy by default, then it shouldn't require too invasive a patch.

Ok. So basically what you need is a parent pointer or some other way
of getting the full sysctl_path. All of the names that show up in /proc
are still present in the ctl_table.

Hmm. In parse_table we actually call sysctl_perm at each path component, I'm not doing that in proc_sysctl.c at the moment but that would be easy to add.

I think I will look at adding the back pointers. Adding the security check during lookup is nice but it won't really give you the context you could use. There may be a point in adding a security check during lookup as well, but I think the way the VFS works there are weird implications there.

Eric

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#20 lore raw

Re: [PATCH] sysctl selinux: Don't look at table->de

In reply to Stephen Smalley
Quoted 2 lines · Stephen Smalley

True, but a system that disables proc is likely a system with a custom policy anyway,

In practice we have to extensively customise policy long before getting to the non-proc stage of optimising for small hardware. The Familiar distribution (used on the iPaQ) has /proc but needs significant policy changes when compared to a typical Fedora workstation. Not only is there the issue that embedded distributions have different daemons and path names to workstations, but the memory constraints mean that even a modular targeted policy is not as small as you desire.

Quoted 4 lines

and dependency on proc is fairly basic to selinux these
days (due to reliance on /proc/self/attr for process attribute manipulation in place of the old selinux syscalls).  Possibly we should just make selinux depend on proc and drop the #ifdef there.

I think that is the correct thing to do. Someone who is prepared to do all the work needed to get a recent SE Linux system operating without /proc will have no problem changing the kernel config scripts and everyone else would be better off not being confused by being offered sets of options that are not viable.

Signature · 11 lines
[email protected]
http://etbe.blogspot.com/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development



--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#21 lore raw

PATCH 1/2 sysctl: Add a parent entry to ctl_table and set the parent entry.

In reply to Stephen Smalley

Add a parent entry into the ctl_table so you can walk the list of parents and find the entire path to a ctl_table entry.

---

This is an incremental patch on top of my previous sysctl work.

 include/linux/sysctl.h |    1 +
 kernel/sysctl.c        |   10 ++++++++++
 2 files changed, 11 insertions(+), 0 deletions(-)
include/linux/sysctl.h +1 -0
index 286e723..24f36f1 100644
@@ -1024,6 +1024,7 @@ struct ctl_table
 	int maxlen;
 	mode_t mode;
 	ctl_table *child;
+	ctl_table *parent;		/* Automatically set */
 	proc_handler *proc_handler;	/* Callback for text formatting */
 	ctl_handler *strategy;		/* Callback function for all r/w */
 	void *extra1;
kernel/sysctl.c +10 -0
index ae6a424..0a5499f 100644
@@ -1232,6 +1232,15 @@ int do_sysctl_strategy (ctl_table *table,
 }
 #endif /* CONFIG_SYSCTL_SYSCALL */
 
+static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
+{
+	for (; table->ctl_name || table->procname; table++) {
+		table->parent = parent;
+		if (table->child)
+			sysctl_set_parent(table, table->child);
+	}
+}
+
 /**
  * register_sysctl_table - register a sysctl hierarchy
  * @table: the top-level table structure
@@ -1311,6 +1320,7 @@ static struct ctl_table_header *__register_sysctl_table(
 	INIT_LIST_HEAD(&tmp->ctl_entry);
 	tmp->used = 0;
 	tmp->unregistering = NULL;
+	sysctl_set_parent(NULL, table);
 	spin_lock(&sysctl_lock);
 	list_add_tail(&tmp->ctl_entry, &root->ctl_entry);
 	spin_unlock(&sysctl_lock);
Signature · 7 lines
1.4.4.1.g278f


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#22 lore raw

PATCH 2/2 sysctl: Restore the selinux path based label lookup for sysctls.

This time instead of generating the generating the paths from proc_dir_entries generate the labels from the names in the sysctl ctl_tables themselves. This removes an unnecessary layer of indirection, allows this to work even when procfs support is not compiled into the kernel, and especially allows it to work now that ctl_tables no longer have a proc_dir_entry field.

I continue passing "proc" into genfs sid although that is complete nonsense to allow existing selinux policies to work without modification.

---
 security/selinux/hooks.c |   43 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 41 insertions(+), 2 deletions(-)
security/selinux/hooks.c +41 -2
index 3a36057..c17a8dd 100644
@@ -1424,6 +1424,41 @@ static int selinux_capable(struct task_struct *tsk, int cap)
 	return task_has_capability(tsk,cap);
 }
 
+static int selinux_sysctl_get_sid(ctl_table *table, u16 tclass, u32 *sid)
+{
+	int buflen, rc;
+	char *buffer, *path, *end;
+
+	rc = -ENOMEM;
+	buffer = (char*)__get_free_page(GFP_KERNEL);
+	if (!buffer)
+		goto out;
+
+	buflen = PAGE_SIZE;
+	end = buffer+buflen;
+	*--end = '\0';
+	buflen--;
+	path = end-1;
+	*path = '/';
+	while (table) {
+		const char *name = table->procname;
+		size_t namelen = strlen(name);
+		buflen -= namelen + 1;
+		if (buflen < 0)
+			goto out_free;
+		end -= namelen;
+		memcpy(end, name, namelen);
+		*--end = '/';
+		path = end;
+		table = table->parent;
+	}
+	rc = security_genfs_sid("proc", path, tclass, sid);
+out_free:
+	free_page((unsigned long)buffer);
+out:
+	return rc;
+}
+
 static int selinux_sysctl(ctl_table *table, int op)
 {
 	int error = 0;
@@ -1438,8 +1473,12 @@ static int selinux_sysctl(ctl_table *table, int op)
 
 	tsec = current->security;
 
-	/* Use the well-defined sysctl SID. */
-	tsid = SECINITSID_SYSCTL;
+	rc = selinux_sysctl_get_sid(table, (op == 0001) ?
+				    SECCLASS_DIR : SECCLASS_FILE, &tsid);
+	if (rc) {
+		/* Default to the well-defined sysctl SID. */
+		tsid = SECINITSID_SYSCTL;
+	}
 
 	/* The op values are "defined" in sysctl.c, thereby creating
 	 * a bad coupling between this module and sysctl.c */
Signature · 7 lines
1.4.4.1.g278f


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
Acked-by on v1 2/2
#23 lore raw

Re: [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls.

Quoted 5 lines · Eric W. Biederman

This time instead of generating the generating the paths from proc_dir_entries generate the labels from the names in the sysctl ctl_tables themselves. This removes an unnecessary layer of indirection, allows this to work even when procfs support is not compiled into the kernel, and especially allows it to work now that ctl_tables no longer have a proc_dir_entry field.

Thanks, looks sane.

Quoted 4 lines

I continue passing "proc" into genfs sid although that is complete nonsense to allow existing selinux policies to work without modification.

Quoted 65 lines
---
 security/selinux/hooks.c |   43 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 41 insertions(+), 2 deletions(-)
security/selinux/hooks.c +41 -2
index 3a36057..c17a8dd 100644
@@ -1424,6 +1424,41 @@ static int selinux_capable(struct task_struct *tsk, int cap)
 	return task_has_capability(tsk,cap);
 }
 
+static int selinux_sysctl_get_sid(ctl_table *table, u16 tclass, u32 *sid)
+{
+	int buflen, rc;
+	char *buffer, *path, *end;
+
+	rc = -ENOMEM;
+	buffer = (char*)__get_free_page(GFP_KERNEL);
+	if (!buffer)
+		goto out;
+
+	buflen = PAGE_SIZE;
+	end = buffer+buflen;
+	*--end = '\0';
+	buflen--;
+	path = end-1;
+	*path = '/';
+	while (table) {
+		const char *name = table->procname;
+		size_t namelen = strlen(name);
+		buflen -= namelen + 1;
+		if (buflen < 0)
+			goto out_free;
+		end -= namelen;
+		memcpy(end, name, namelen);
+		*--end = '/';
+		path = end;
+		table = table->parent;
+	}
+	rc = security_genfs_sid("proc", path, tclass, sid);
+out_free:
+	free_page((unsigned long)buffer);
+out:
+	return rc;
+}
+
 static int selinux_sysctl(ctl_table *table, int op)
 {
 	int error = 0;
@@ -1438,8 +1473,12 @@ static int selinux_sysctl(ctl_table *table, int op)
 
 	tsec = current->security;
 
-	/* Use the well-defined sysctl SID. */
-	tsid = SECINITSID_SYSCTL;
+	rc = selinux_sysctl_get_sid(table, (op == 0001) ?
+				    SECCLASS_DIR : SECCLASS_FILE, &tsid);
+	if (rc) {
+		/* Default to the well-defined sysctl SID. */
+		tsid = SECINITSID_SYSCTL;
+	}
 
 	/* The op values are "defined" in sysctl.c, thereby creating
 	 * a bad coupling between this module and sysctl.c */
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#24 lore raw

Re: [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls.

Quoted 7 lines · Stephen Smalley
Quoted 5 lines · Eric W. Biederman

This time instead of generating the generating the paths from proc_dir_entries generate the labels from the names in the sysctl ctl_tables themselves. This removes an unnecessary layer of indirection, allows this to work even when procfs support is not compiled into the kernel, and especially allows it to work now that ctl_tables no longer have a proc_dir_entry field.

Quoted 8 lines

Thanks, looks sane.

Quoted 4 lines

I continue passing "proc" into genfs sid although that is complete nonsense to allow existing selinux policies to work without modification.

Hmmm...but in testing the patch, I don't seem to (consistently) reach these checks when accessing via /proc/sys. I see that you are caching the mode information and using it in some cases rather than calling the sysctl_perm function.

One related but separate issue is that the /proc/sys inode labeling is also affected by the sysctl patch series. Those inodes used to be labeled by selinux_proc_get_sid (from selinux_d_instantiate), but that no longer works, so they now fall back to the superblock SID (generic proc label). That changes the inode permission checks on an attempt to access a /proc/sys node and will likely cause denials under current policy for confined domains since one wouldn't generally be writing to the generic proc label. If you always called sysctl_perm from the proc sysctl code, we could possibly dispense with inode permission checking on those inodes, e.g. marking them private.

Quoted 66 lines
Quoted 66 lines
---
 security/selinux/hooks.c |   43 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 41 insertions(+), 2 deletions(-)
security/selinux/hooks.c +41 -2
index 3a36057..c17a8dd 100644
@@ -1424,6 +1424,41 @@ static int selinux_capable(struct task_struct *tsk, int cap)
 	return task_has_capability(tsk,cap);
 }
 
+static int selinux_sysctl_get_sid(ctl_table *table, u16 tclass, u32 *sid)
+{
+	int buflen, rc;
+	char *buffer, *path, *end;
+
+	rc = -ENOMEM;
+	buffer = (char*)__get_free_page(GFP_KERNEL);
+	if (!buffer)
+		goto out;
+
+	buflen = PAGE_SIZE;
+	end = buffer+buflen;
+	*--end = '\0';
+	buflen--;
+	path = end-1;
+	*path = '/';
+	while (table) {
+		const char *name = table->procname;
+		size_t namelen = strlen(name);
+		buflen -= namelen + 1;
+		if (buflen < 0)
+			goto out_free;
+		end -= namelen;
+		memcpy(end, name, namelen);
+		*--end = '/';
+		path = end;
+		table = table->parent;
+	}
+	rc = security_genfs_sid("proc", path, tclass, sid);
+out_free:
+	free_page((unsigned long)buffer);
+out:
+	return rc;
+}
+
 static int selinux_sysctl(ctl_table *table, int op)
 {
 	int error = 0;
@@ -1438,8 +1473,12 @@ static int selinux_sysctl(ctl_table *table, int op)
 
 	tsec = current->security;
 
-	/* Use the well-defined sysctl SID. */
-	tsid = SECINITSID_SYSCTL;
+	rc = selinux_sysctl_get_sid(table, (op == 0001) ?
+				    SECCLASS_DIR : SECCLASS_FILE, &tsid);
+	if (rc) {
+		/* Default to the well-defined sysctl SID. */
+		tsid = SECINITSID_SYSCTL;
+	}
 
 	/* The op values are "defined" in sysctl.c, thereby creating
 	 * a bad coupling between this module and sysctl.c */
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#25 lore raw

Re: [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls.

Quoted 13 lines · Stephen Smalley
Quoted 12 lines · Stephen Smalley
Quoted 5 lines · Eric W. Biederman

This time instead of generating the generating the paths from proc_dir_entries generate the labels from the names in the sysctl ctl_tables themselves. This removes an unnecessary layer of indirection, allows this to work even when procfs support is not compiled into the kernel, and especially allows it to work now that ctl_tables no longer have a proc_dir_entry field.

Thanks, looks sane.

Quoted 3 lines

I continue passing "proc" into genfs sid although that is complete nonsense to allow existing selinux policies to work without modification.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Hmmm...but in testing the patch, I don't seem to (consistently) reach these checks when accessing via /proc/sys. I see that you are caching the mode information and using it in some cases rather than calling the sysctl_perm function.

Actually, on further inspection, it looks like the real issue is the "path" name generation; "cat /proc/sys/kernel/modprobe" yields a call to security_genfs_sid() with just "/modprobe" rather than the expected "/sys/kernel/modprobe". Which likewise leaves us with the generic proc label, just as with the inode permission check, so I end up seeing checks against it only.

Quoted 10 lines

One related but separate issue is that the /proc/sys inode labeling is also affected by the sysctl patch series. Those inodes used to be labeled by selinux_proc_get_sid (from selinux_d_instantiate), but that no longer works, so they now fall back to the superblock SID (generic proc label). That changes the inode permission checks on an attempt to access a /proc/sys node and will likely cause denials under current policy for confined domains since one wouldn't generally be writing to the generic proc label. If you always called sysctl_perm from the proc sysctl code, we could possibly dispense with inode permission checking on those inodes, e.g. marking them private.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#26 lore raw

Re: [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls.

Quoted 6 lines · Stephen Smalley

Actually, on further inspection, it looks like the real issue is the "path" name generation; "cat /proc/sys/kernel/modprobe" yields a call to security_genfs_sid() with just "/modprobe" rather than the expected "/sys/kernel/modprobe". Which likewise leaves us with the generic proc label, just as with the inode permission check, so I end up seeing checks against it only.

Ok. It looks like two silly thing are going on here.
I failed to register the root sysctl table, so none of the parent pointers got set.

I didn't prepend /sys in the compatibility code, so for something with the parent pointers set you would have gotten "/kernel/modprobe" instead of /sys/kernel/modprobe"

Sorry about that.

I think the patch below will fix it.

Eric

include/linux/sysctl.h +0 -2
index 24f36f1..f316854 100644
@@ -929,8 +929,6 @@ extern struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev);
 extern void sysctl_head_finish(struct ctl_table_header *prev);
 extern int sysctl_perm(struct ctl_table *table, int op);
 
-extern void sysctl_init(void);
-
 typedef struct ctl_table ctl_table;
 
 typedef int ctl_handler (ctl_table *table, int __user *name, int nlen,
kernel/sysctl.c +8 -0
index 0a5499f..0bb2c5f 100644
@@ -1241,6 +1241,14 @@ static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
 	}
 }
 
+static __init int sysctl_init(void)
+{
+	sysctl_set_parent(NULL, root_table);
+	return 0;
+}
+
+core_initcall(sysctl_init);
+
 /**
  * register_sysctl_table - register a sysctl hierarchy
  * @table: the top-level table structure
security/selinux/hooks.c +6 -0
index c17a8dd..aad2697 100644
@@ -1452,6 +1452,12 @@ static int selinux_sysctl_get_sid(ctl_table *table, u16 tclass, u32 *sid)
 		path = end;
 		table = table->parent;
 	}
+	buflen -= 4;
+	if (buflen < 0)
+		goto out_free;
+	end -= 4;
+	memcpy(end, "/sys", 4);
+	path = end;
 	rc = security_genfs_sid("proc", path, tclass, sid);
 out_free:
 	free_page((unsigned long)buffer);

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#27 lore raw

Re: [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls.

Quoted 13 lines · Eric W. Biederman
Quoted 6 lines · Stephen Smalley

Actually, on further inspection, it looks like the real issue is the "path" name generation; "cat /proc/sys/kernel/modprobe" yields a call to security_genfs_sid() with just "/modprobe" rather than the expected "/sys/kernel/modprobe". Which likewise leaves us with the generic proc label, just as with the inode permission check, so I end up seeing checks against it only.

Ok. It looks like two silly thing are going on here.
I failed to register the root sysctl table, so none of the parent pointers got set.

Quoted 7 lines

I didn't prepend /sys in the compatibility code, so for something with the parent pointers set you would have gotten "/kernel/modprobe" instead of /sys/kernel/modprobe"

Sorry about that.

I think the patch below will fix it.

Yes, thanks - this appears to correct the name generation and thus the resulting SID computation for the selinux sysctl checks.

Quoted 52 lines

Eric

include/linux/sysctl.h +0 -2
index 24f36f1..f316854 100644
@@ -929,8 +929,6 @@ extern struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev);
 extern void sysctl_head_finish(struct ctl_table_header *prev);
 extern int sysctl_perm(struct ctl_table *table, int op);
 
-extern void sysctl_init(void);
-
 typedef struct ctl_table ctl_table;
 
 typedef int ctl_handler (ctl_table *table, int __user *name, int nlen,
kernel/sysctl.c +8 -0
index 0a5499f..0bb2c5f 100644
@@ -1241,6 +1241,14 @@ static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
 	}
 }
 
+static __init int sysctl_init(void)
+{
+	sysctl_set_parent(NULL, root_table);
+	return 0;
+}
+
+core_initcall(sysctl_init);
+
 /**
  * register_sysctl_table - register a sysctl hierarchy
  * @table: the top-level table structure
security/selinux/hooks.c +6 -0
index c17a8dd..aad2697 100644
@@ -1452,6 +1452,12 @@ static int selinux_sysctl_get_sid(ctl_table *table, u16 tclass, u32 *sid)
 		path = end;
 		table = table->parent;
 	}
+	buflen -= 4;
+	if (buflen < 0)
+		goto out_free;
+	end -= 4;
+	memcpy(end, "/sys", 4);
+	path = end;
 	rc = security_genfs_sid("proc", path, tclass, sid);
 out_free:
 	free_page((unsigned long)buffer);
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#28 lore raw

Re: [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls.

In reply to Stephen Smalley
Quoted 11 lines · Stephen Smalley

One related but separate issue is that the /proc/sys inode labeling is also affected by the sysctl patch series. Those inodes used to be labeled by selinux_proc_get_sid (from selinux_d_instantiate), but that no longer works, so they now fall back to the superblock SID (generic proc label). That changes the inode permission checks on an attempt to access a /proc/sys node and will likely cause denials under current policy for confined domains since one wouldn't generally be writing to the generic proc label. If you always called sysctl_perm from the proc sysctl code, we could possibly dispense with inode permission checking on those inodes, e.g. marking them private.

Like this?

It seems a little weird but I'm happy with it if you are.

Eric

fs/proc/proc_sysctl.c +1 -0
index b9d59c0..7d6f7c7 100644
@@ -47,6 +47,7 @@ static struct inode *proc_sys_make_inode(struct inode *dir, struct ctl_table *ta
 	inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
 	inode->i_op = &proc_sys_inode_operations;
 	inode->i_fop = &proc_sys_file_operations;
+	inode->i_flags |= S_PRIVATE; /* tell selinux to ignore this inode */
 	proc_sys_refresh_inode(inode, table);
 out:
 	return inode;

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#29 lore raw

Re: [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls.

Quoted 25 lines · Eric W. Biederman
Quoted 11 lines · Stephen Smalley

One related but separate issue is that the /proc/sys inode labeling is also affected by the sysctl patch series. Those inodes used to be labeled by selinux_proc_get_sid (from selinux_d_instantiate), but that no longer works, so they now fall back to the superblock SID (generic proc label). That changes the inode permission checks on an attempt to access a /proc/sys node and will likely cause denials under current policy for confined domains since one wouldn't generally be writing to the generic proc label. If you always called sysctl_perm from the proc sysctl code, we could possibly dispense with inode permission checking on those inodes, e.g. marking them private.

Like this?

It seems a little weird but I'm happy with it if you are.

Eric

fs/proc/proc_sysctl.c +0 -0
index b9d59c0..7d6f7c7 100644

fs/proc/proc_sysctl.c static struct inode *proc_sys_make_inode(struct inode *dir, struct ctl_table *ta · line 53

Quoted 7 lines
fs/proc/proc_sysctl.c +1 -0
@@ -47,6 +47,7 @@ static struct inode *proc_sys_make_inode(struct inode *dir, struct ctl_table *ta
 	inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
 	inode->i_op = &proc_sys_inode_operations;
 	inode->i_fop = &proc_sys_file_operations;
+	inode->i_flags |= S_PRIVATE; /* tell selinux to ignore this inode */
 	proc_sys_refresh_inode(inode, table);
 out:
 	return inode;

Hmmm...turns out to not be quite enough, as the /proc/sys inodes aren't truly private to the fs, so we can run into them in a variety of security hooks beyond just the inode hooks, such as security_file_permission (when reading and writing them via the vfs helpers), security_sb_mount (when mounting other filesystems on directories in proc like binfmt_misc), and deeper within the security module itself (as in flush_unauthorized_files upon inheritance across execve). So I think we have to add an IS_PRIVATE() guard within SELinux, as below. Note however that the use of the private flag here could be confusing, as these inodes are _not_ private to the fs, are exposed to userspace, and security modules must implement the sysctl hook to get any access control over them.

security/selinux/hooks.c +3 -0
index 65fb5e8..21bf2f0 100644
@@ -1078,6 +1077,9 @@ static int inode_has_perm(struct task_st
 	struct inode_security_struct *isec;
 	struct avc_audit_data ad;
 
+	if (unlikely (IS_PRIVATE (inode)))
+		return 0;
+
 	tsec = tsk->security;
 	isec = inode->i_security;
 
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#30 lore raw

Re: [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls.

Quoted 13 lines · Stephen Smalley

Hmmm...turns out to not be quite enough, as the /proc/sys inodes aren't truly private to the fs, so we can run into them in a variety of security hooks beyond just the inode hooks, such as security_file_permission (when reading and writing them via the vfs helpers), security_sb_mount (when mounting other filesystems on directories in proc like binfmt_misc), and deeper within the security module itself (as in flush_unauthorized_files upon inheritance across execve). So I think we have to add an IS_PRIVATE() guard within SELinux, as below. Note however that the use of the private flag here could be confusing, as these inodes are _not_ private to the fs, are exposed to userspace, and security modules must implement the sysctl hook to get any access control over them.

Agreed, the naming is confusing, and using private here doesn't quite feel right.

A practical question is: Will we ever encounter these inodes in the inode_init() path from superblock_init? If all of the accesses that we care about go through inode_doinit_with_dentry we can just walk the dcache to get the names, and that should work for the normal proc case as well.

A somewhat related question: How do you handle security labels for sysfs? No fine grained security yet.

If it doesn't look easy to solve this another way I will certainly go with marking the inodes private.

Eric

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#31 lore raw

Re: [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls.

Quoted 16 lines · Eric W. Biederman
Quoted 13 lines · Stephen Smalley

Hmmm...turns out to not be quite enough, as the /proc/sys inodes aren't truly private to the fs, so we can run into them in a variety of security hooks beyond just the inode hooks, such as security_file_permission (when reading and writing them via the vfs helpers), security_sb_mount (when mounting other filesystems on directories in proc like binfmt_misc), and deeper within the security module itself (as in flush_unauthorized_files upon inheritance across execve). So I think we have to add an IS_PRIVATE() guard within SELinux, as below. Note however that the use of the private flag here could be confusing, as these inodes are _not_ private to the fs, are exposed to userspace, and security modules must implement the sysctl hook to get any access control over them.

Quoted 5 lines

Agreed, the naming is confusing, and using private here doesn't quite feel right.

A practical question is: Will we ever encounter these inodes in the inode_init() path from superblock_init?

Possibly, during setup upon initial policy load (initiated by /sbin/init these days) from selinux_complete_init, as early userspace may have already been accessing them.

Quoted 4 lines

If all of the accesses
that we care about go through inode_doinit_with_dentry we can just walk the dcache to get the names, and that should work for the normal proc case as well.

Walking the proc_dir_entry tree (or the ctl_table tree) is preferable as it is a stable, user-immutable representation. Also avoids taking the dcache lock.

Quoted 2 lines

A somewhat related question: How do you handle security labels for sysfs? No fine grained security yet.

Right, they are all mapped to a single label presently. I was thinking of handling that from userspace after introducing a setxattr handler for sysfs and a way to preserve the SID on the entry (likely caching it in the sysfs_dirent and propagating that to the inode when the inode is populated from the sysfs_dirent). Then early userspace could walk sysfs and apply finer-grained labeling from a configuration.

Quoted 2 lines

If it doesn't look easy to solve this another way I will certainly go with marking the inodes private.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#32 lore raw

Re: [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls.

Quoted 3 lines · Stephen Smalley

Possibly, during setup upon initial policy load (initiated by /sbin/init these days) from selinux_complete_init, as early userspace may have already been accessing them.

I believe if we chose we could walk the dentry tree under the root inode and find all of these.

Quoted 8 lines
Quoted 4 lines

If all of the accesses
that we care about go through inode_doinit_with_dentry we can just walk the dcache to get the names, and that should work for the normal proc case as well.

Walking the proc_dir_entry tree (or the ctl_table tree) is preferable as it is a stable, user-immutable representation. Also avoids taking the dcache lock.

The dcache lock is valid. Since the per filesystem dentry tree is just a mirror of the filesystem data there is no advantage over using the proc_dir_entry or ctl_table tree. (If you start messing with mounts that is another matter.

Quoted 2 lines
Quoted 2 lines

If it doesn't look easy to solve this another way I will certainly go with marking the inodes private.

I hereby conclude this doesn't look easy enough to solve another way, to get it solved in a timely manner. Since the cost is only 2 lines of code to use private inodes if we want to fix this later it should not be difficult.

Eric

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#33 lore raw

cover sysctl cleanup selinux fixes

Andrew these are a set up simple fixes against the rollup you sent me last night that should leave selinux working and should close out the last of the outstanding issue with my sysctl cleanup.

Knowing how you organize I expect you will want to file most of these as fix patches.

Patch 1 sysctl: Remove declaration of nonexistent sysctl_init This is a small fix against "sysctl: Reimplement the sysctl proc support" where I remove sysctl_init() but forgot to remove it's prototype in sysctl.h

Patch 2 sysctl: Set the parent field in the root sysctl table This is a small fix against
"sysctl: Add a parent entry to ctl_table and set the parent entry." where I forgot to call sysctl_set_parent on the root sysctl table.

Patch 3: sysctl: Fix selinux_sysctl_getsid This is a small fix against
"sysctl: Restore the old selinux sysctl handling."

Patch 4: selinux: Enhance selinux to always ignore private inodes Patch 5: sysctl: Hide the sysctl proc inodes from selinux

Eric

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#34 lore raw

PATCH 1/5 sysctl: Remove declaration of nonexistent sysctl_init()

---
 include/linux/sysctl.h |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
include/linux/sysctl.h +0 -2
index 538f6d2..b5c2b3e 100644
@@ -929,8 +929,6 @@ extern struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev);
 extern void sysctl_head_finish(struct ctl_table_header *prev);
 extern int sysctl_perm(struct ctl_table *table, int op);
 
-extern void sysctl_init(void);
-
 typedef struct ctl_table ctl_table;
 
 typedef int ctl_handler (ctl_table *table, int __user *name, int nlen,
Signature · 7 lines
1.4.4.1.g278f


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#35 lore raw

PATCH 2/5 sysctl: Set the parent field in the root sysctl table

Oops I goofed and forgot to set the parent in the root sysctl table, the rest are covered by register_sysctl_table.

---
 kernel/sysctl.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
kernel/sysctl.c +8 -0
index d3a84fc..aa7d69e 100644
@@ -1296,6 +1296,14 @@ static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
 	}
 }
 
+static __init int sysctl_init(void)
+{
+	sysctl_set_parent(NULL, root_table);
+	return 0;
+}
+
+core_initcall(sysctl_init);
+
 /**
  * register_sysctl_table - register a sysctl hierarchy
  * @table: the top-level table structure
Signature · 7 lines
1.4.4.1.g278f


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#36 lore raw

PATCH 3/5 sysctl: Fix the selinux_sysctl_get_sid

I goofed and when reenabling the fine grained selinux labels for sysctls and forgot to add the "/sys" prefix before consulting the policy database. When computing the same path using proc_dir_entries we got the "/sys" for free as it was part of the tree, but it isn't true for clt_table trees.

---
 security/selinux/hooks.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
security/selinux/hooks.c +6 -0
index 47fb937..de16b9f 100644
@@ -1445,6 +1445,12 @@ static int selinux_sysctl_get_sid(ctl_table *table, u16 tclass, u32 *sid)
 		path = end;
 		table = table->parent;
 	}
+	buflen -= 4;
+	if (buflen < 0)
+		goto out_free;
+	end -= 4;
+	memcpy(end, "/sys", 4);
+	path = end;
 	rc = security_genfs_sid("proc", path, tclass, sid);
 out_free:
 	free_page((unsigned long)buffer);
Signature · 7 lines
1.4.4.1.g278f


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#37 lore raw

PATCH 4/5 selinux: Enhance selinux to always ignore private inodes.

From: Stephen Smalley <[email protected]>

Hmmm...turns out to not be quite enough, as the /proc/sys inodes aren't truly private to the fs, so we can run into them in a variety of security hooks beyond just the inode hooks, such as security_file_permission (when reading and writing them via the vfs helpers), security_sb_mount (when mounting other filesystems on directories in proc like binfmt_misc), and deeper within the security module itself (as in flush_unauthorized_files upon inheritance across execve). So I think we have to add an IS_PRIVATE() guard within SELinux, as below. Note however that the use of the private flag here could be confusing, as these inodes are _not_ private to the fs, are exposed to userspace, and security modules must implement the sysctl hook to get any access control over them.

---
 security/selinux/hooks.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
security/selinux/hooks.c +3 -0
index de16b9f..ff9fccc 100644
@@ -1077,6 +1077,9 @@ static int inode_has_perm(struct task_struct *tsk,
 	struct inode_security_struct *isec;
 	struct avc_audit_data ad;
 
+	if (unlikely (IS_PRIVATE (inode)))
+		return 0;
+
 	tsec = tsk->security;
 	isec = inode->i_security;
 
Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#38 lore raw

PATCH 5/5 sysctl: Hide the sysctl proc inodes from selinux.

Since the security checks are applied on each read and write of a sysctl file, just like they are applied when calling sys_sysctl, they are redundant on the standard VFS constructs. Since it is difficult to compute the security labels on the standard VFS constructs we just mark the sysctl inodes in proc private so selinux won't even bother with them.

---
 fs/proc/proc_sysctl.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
fs/proc/proc_sysctl.c +1 -0
index bb16a1e..20e8cbb 100644
@@ -47,6 +47,7 @@ static struct inode *proc_sys_make_inode(struct inode *dir, struct ctl_table *ta
 	inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
 	inode->i_op = &proc_sys_inode_operations;
 	inode->i_fop = &proc_sys_file_operations;
+	inode->i_flags |= S_PRIVATE; /* tell selinux to ignore this inode */
 	proc_sys_refresh_inode(inode, table);
 out:
 	return inode;
Signature · 7 lines
1.4.4.1.g278f


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#39 lore raw

Re: [PATCH 4/5] selinux: Enhance selinux to always ignore private inodes.

In reply to Eric W. Biederman
Quoted 14 lines · Eric W. Biederman

From: Stephen Smalley <[email protected]>

Hmmm...turns out to not be quite enough, as the /proc/sys inodes aren't truly private to the fs, so we can run into them in a variety of security hooks beyond just the inode hooks, such as security_file_permission (when reading and writing them via the vfs helpers), security_sb_mount (when mounting other filesystems on directories in proc like binfmt_misc), and deeper within the security module itself (as in flush_unauthorized_files upon inheritance across execve). So I think we have to add an IS_PRIVATE() guard within SELinux, as below. Note however that the use of the private flag here could be confusing, as these inodes are _not_ private to the fs, are exposed to userspace, and security modules must implement the sysctl hook to get any access control over them.

Quoted 20 lines
---
 security/selinux/hooks.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
security/selinux/hooks.c +3 -0
index de16b9f..ff9fccc 100644
@@ -1077,6 +1077,9 @@ static int inode_has_perm(struct task_struct *tsk,
 	struct inode_security_struct *isec;
 	struct avc_audit_data ad;
 
+	if (unlikely (IS_PRIVATE (inode)))
+		return 0;
+
 	tsec = tsk->security;
 	isec = inode->i_security;
 
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
Acked-by on v1 3/5
#40 lore raw

Re: [PATCH 3/5] sysctl: Fix the selinux_sysctl_get_sid

In reply to Eric W. Biederman
Quoted 7 lines · Eric W. Biederman

I goofed and when reenabling the fine grained selinux labels for sysctls and forgot to add the "/sys" prefix before consulting the policy database. When computing the same path using proc_dir_entries we got the "/sys" for free as it was part of the tree, but it isn't true for clt_table trees.

Quoted 21 lines
---
 security/selinux/hooks.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
security/selinux/hooks.c +6 -0
index 47fb937..de16b9f 100644
@@ -1445,6 +1445,12 @@ static int selinux_sysctl_get_sid(ctl_table *table, u16 tclass, u32 *sid)
 		path = end;
 		table = table->parent;
 	}
+	buflen -= 4;
+	if (buflen < 0)
+		goto out_free;
+	end -= 4;
+	memcpy(end, "/sys", 4);
+	path = end;
 	rc = security_genfs_sid("proc", path, tclass, sid);
 out_free:
 	free_page((unsigned long)buffer);
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#41 lore raw

Re: [PATCH 0/5] sysctl cleanup selinux fixes

In reply to Eric W. Biederman
Quoted 4 lines · On Thu, 08 Feb 2007 15:51:15 -0700 [email protected] (Eric W. Biederman)…

Patch 3: sysctl: Fix selinux_sysctl_getsid This is a small fix against
"sysctl: Restore the old selinux sysctl handling."

I cannot locate such a patch. I just gave up and plastered the fixes at end-of-series.

#42 lore raw

Re: [PATCH 0/5] sysctl cleanup selinux fixes

Quoted 10 lines · Andrew Morton
Quoted 4 lines · On Thu, 08 Feb 2007 15:51:15 -0700 [email protected] (Eric W. Biederman)…

Patch 3: sysctl: Fix selinux_sysctl_getsid This is a small fix against
"sysctl: Restore the old selinux sysctl handling."

I cannot locate such a patch. I just gave up and plastered the fixes at end-of-series.

Ok. Sorry. I'm guessing one of us (probably me) renamed that one. I have this habit of rewriting my comments as they go out the door, so they are more readable.

Eric

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.