e6c876d8b8
https://source.android.com/security/bulletin/2021-08-01 CVE-2020-14381 CVE-2021-3347 CVE-2021-28375 * tag 'ASB-2021-08-05_4.19-stable' of https://github.com/aosp-mirror/kernel_common: Linux 4.19.200 ARM: dts: versatile: Fix up interrupt controller node names cifs: fix the out of range assignment to bit fields in parse_server_interfaces firmware: arm_scmi: Fix range check for the maximum number of pending messages firmware: arm_scmi: Fix possible scmi_linux_errmap buffer overflow hfs: add lock nesting notation to hfs_find_init hfs: fix high memory mapping in hfs_bnode_read hfs: add missing clean-up in hfs_fill_super sctp: move 198 addresses from unusable to private scope net: annotate data race around sk_ll_usec net/802/garp: fix memleak in garp_request_join() net/802/mrp: fix memleak in mrp_request_join() workqueue: fix UAF in pwq_unbound_release_workfn() af_unix: fix garbage collect vs MSG_PEEK net: split out functions related to registering inflight socket files KVM: x86: determine if an exception has an error code only when injecting it. iio: dac: ds4422/ds4424 drop of_node check selftest: fix build error in tools/testing/selftests/vm/userfaultfd.c ANDROID: staging: ion: move buffer kmap from begin/end_cpu_access() Linux 4.19.199 xhci: add xhci_get_virt_ep() helper spi: spi-fsl-dspi: Fix a resource leak in an error handling path PCI: Mark AMD Navi14 GPU ATS as broken btrfs: compression: don't try to compress if we don't have enough pages iio: accel: bma180: Fix BMA25x bandwidth register values iio: accel: bma180: Use explicit member assignment net: bcmgenet: ensure EXT_ENERGY_DET_MASK is clear net: dsa: mv88e6xxx: use correct .stats_set_histogram() on Topaz KVM: Use kvm_pfn_t for local PFN variable in hva_to_pfn_remapped() KVM: do not allow mapping valid but non-reference-counted pages KVM: do not assume PTE is writable after follow_pfn drm: Return -ENOTTY for non-drm ioctls nds32: fix up stack guard gap selftest: use mmap instead of posix_memalign to allocate memory ixgbe: Fix packet corruption due to missing DMA sync media: ngene: Fix out-of-bounds bug in ngene_command_config_free_buf() tracing: Fix bug in rb_per_cpu_empty() that might cause deadloop. usb: dwc2: gadget: Fix sending zero length packet in DDMA mode. USB: serial: cp210x: add ID for CEL EM3588 USB ZigBee stick USB: serial: cp210x: fix comments for GE CS1000 USB: serial: option: add support for u-blox LARA-R6 family usb: renesas_usbhs: Fix superfluous irqs happen after usb_pkt_pop() usb: max-3421: Prevent corruption of freed memory USB: usb-storage: Add LaCie Rugged USB3-FW to IGNORE_UAS usb: hub: Fix link power management max exit latency (MEL) calculations usb: hub: Disable USB 3 device initiated lpm if exit latency is too high KVM: PPC: Book3S: Fix H_RTAS rets buffer overflow xhci: Fix lost USB 2 remote wake ALSA: sb: Fix potential ABBA deadlock in CSP driver ALSA: usb-audio: Add registration quirk for JBL Quantum headsets s390/ftrace: fix ftrace_update_ftrace_func implementation Revert "MIPS: add PMD table accounting into MIPS'pmd_alloc_one" proc: Avoid mixing integer types in mem_rw() drm/panel: raspberrypi-touchscreen: Prevent double-free net: sched: cls_api: Fix the the wrong parameter sctp: update active_key for asoc when old key is being replaced Revert "USB: quirks: ignore remote wake-up on Fibocom L850-GL LTE modem" nvme-pci: don't WARN_ON in nvme_reset_work if ctrl.state is not RESETTING net/sched: act_skbmod: Skip non-Ethernet packets net/tcp_fastopen: fix data races around tfo_active_disable_stamp spi: cadence: Correct initialisation of runtime PM again scsi: target: Fix protect handling in WRITE SAME(32) scsi: iscsi: Fix iface sysfs attr detection netrom: Decrease sock refcount when sock timers expire KVM: PPC: Fix kvm_arch_vcpu_ioctl vcpu_load leak net: decnet: Fix sleeping inside in af_decnet net: fix uninit-value in caif_seqpkt_sendmsg bpftool: Check malloc return value in mount_bpffs_for_pin s390/bpf: Perform r1 range checking before accessing jit->seen_reg[r1] liquidio: Fix unintentional sign extension issue on left shift of u16 spi: mediatek: fix fifo rx mode perf probe-file: Delete namelist in del_events() on the error path perf test bpf: Free obj_buf perf lzma: Close lzma stream on exit perf dso: Fix memory leak in dso__new_map() perf probe: Fix dso->nsinfo refcounting perf map: Fix dso->nsinfo refcounting nvme-pci: do not call nvme_dev_remove_admin from nvme_remove ipv6: fix 'disable_policy' for fwd packets igb: Fix position of assignment to *ring igb: Check if num of q_vectors is smaller than max before array access iavf: Fix an error handling path in 'iavf_probe()' e1000e: Fix an error handling path in 'e1000_probe()' fm10k: Fix an error handling path in 'fm10k_probe()' igb: Fix an error handling path in 'igb_probe()' ixgbe: Fix an error handling path in 'ixgbe_probe()' igb: Fix use-after-free error during reset net: ip_tunnel: fix mtu calculation for ETHER tunnel devices udp: annotate data races around unix_sk(sk)->gso_size bpftool: Properly close va_list 'ap' by va_end() on error ipv6: tcp: drop silly ICMPv6 packet too big messages tcp: annotate data races around tp->mtu_info dma-buf/sync_file: Don't leak fences on merge failure net: validate lwtstate->data before returning from skb_tunnel_info() net: send SYNACK packet with accepted fwmark net: ti: fix UAF in tlan_remove_one net: qcom/emac: fix UAF in emac_remove net: moxa: fix UAF in moxart_mac_probe net: bcmgenet: Ensure all TX/RX queues DMAs are disabled net: bridge: sync fdb to new unicast-filtering ports netfilter: ctnetlink: suspicious RCU usage in ctnetlink_dump_helpinfo net: ipv6: fix return value of ip6_skb_dst_mtu net: dsa: mv88e6xxx: enable .rmu_disable() on Topaz dm writecache: fix writing beyond end of underlying device when shrinking dm writecache: return the exact table values that were set mm: slab: fix kmem_cache_create failed when sysfs node not destroyed sched/fair: Fix CFS bandwidth hrtimer expiry type scsi: libfc: Fix array index out of bound exception scsi: libsas: Add LUN number check in .slave_alloc callback scsi: aic7xxx: Fix unintentional sign extension issue on left shift of u8 rtc: max77686: Do not enforce (incorrect) interrupt trigger type kbuild: mkcompile_h: consider timestamp if KBUILD_BUILD_TIMESTAMP is set thermal/core: Correct function name thermal_zone_device_unregister() arm64: dts: ls208xa: remove bus-num from dspi node soc/tegra: fuse: Fix Tegra234-only builds ARM: dts: stm32: move stmmac axi config in ethernet node on stm32mp15 ARM: dts: stm32: fix i2c node name on stm32f746 to prevent warnings ARM: dts: rockchip: fix supply properties in io-domains nodes arm64: dts: juno: Update SCPI nodes as per the YAML schema ARM: dts: stm32: fix timer nodes on STM32 MCU to prevent warnings ARM: dts: stm32: fix RCC node name on stm32f429 MCU ARM: dts: stm32: fix gpio-keys node on STM32 MCU boards rtc: mxc_v2: add missing MODULE_DEVICE_TABLE ARM: imx: pm-imx5: Fix references to imx5_cpu_suspend_info ARM: dts: imx6: phyFLEX: Fix UART hardware flow control ARM: dts: Hurricane 2: Fix NAND nodes names ARM: dts: BCM63xx: Fix NAND nodes names ARM: NSP: dts: fix NAND nodes names ARM: Cygnus: dts: fix NAND nodes names ARM: brcmstb: dts: fix NAND nodes names reset: ti-syscon: fix to_ti_syscon_reset_data macro arm64: dts: rockchip: Fix power-controller node names for rk3328 ARM: dts: rockchip: Fix power-controller node names for rk3288 ARM: dts: rockchip: Fix IOMMU nodes properties on rk322x ARM: dts: rockchip: Fix the timer clocks order arm64: dts: rockchip: fix pinctrl sleep nodename for rk3399.dtsi ARM: dts: rockchip: fix pinctrl sleep nodename for rk3036-kylin and rk3288 ARM: dts: gemini: add device_type on pci ARM: dts: gemini: rename mdio to the right name ANDROID: generate_initcall_order.pl: Use two dash long options for llvm-nm Revert "media: subdev: disallow ioctl for saa6588/davinci" ANDROID: GKI: fix up crc change in ip.h Linux 4.19.198 seq_file: disallow extremely large seq buffer allocations scsi: scsi_dh_alua: Fix signedness bug in alua_rtpg() net: bridge: multicast: fix PIM hello router port marking race MIPS: vdso: Invalid GIC access through VDSO mips: disable branch profiling in boot/decompress.o mips: always link byteswap helpers into decompressor scsi: be2iscsi: Fix an error handling path in beiscsi_dev_probe() ARM: dts: imx6q-dhcom: Add gpios pinctrl for i2c bus recovery ARM: dts: imx6q-dhcom: Fix ethernet plugin detection problems ARM: dts: imx6q-dhcom: Fix ethernet reset time properties ARM: dts: am437x: align ti,pindir-d0-out-d1-in property with dt-shema ARM: dts: am335x: align ti,pindir-d0-out-d1-in property with dt-shema memory: fsl_ifc: fix leak of private memory on probe failure memory: fsl_ifc: fix leak of IO mapping on probe failure reset: bail if try_module_get() fails ARM: dts: BCM5301X: Fixup SPI binding ARM: dts: r8a7779, marzen: Fix DU clock names arm64: dts: renesas: v3msk: Fix memory size rtc: fix snprintf() checking in is_rtc_hctosys() memory: atmel-ebi: add missing of_node_put for loop iteration ARM: dts: exynos: fix PWM LED max brightness on Odroid XU4 ARM: dts: exynos: fix PWM LED max brightness on Odroid HC1 ARM: dts: exynos: fix PWM LED max brightness on Odroid XU/XU3 reset: a10sr: add missing of_match_table reference hexagon: use common DISCARDS macro NFSv4/pNFS: Don't call _nfs4_pnfs_v3_ds_connect multiple times ALSA: isa: Fix error return code in snd_cmi8330_probe() virtio_net: move tx vq operation under tx queue lock x86/fpu: Limit xstate copy size in xstateregs_set() PCI: iproc: Support multi-MSI only on uniprocessor kernel PCI: iproc: Fix multi-MSI base vector number allocation ubifs: Set/Clear I_LINKABLE under i_lock for whiteout inode nfs: fix acl memory leak of posix_acl_create() watchdog: aspeed: fix hardware timeout calculation um: fix error return code in winch_tramp() um: fix error return code in slip_open() NFSv4: Initialise connection to the server in nfs4_alloc_client() power: supply: rt5033_battery: Fix device tree enumeration PCI/sysfs: Fix dsm_label_utf16s_to_utf8s() buffer overrun f2fs: add MODULE_SOFTDEP to ensure crc32 is included in the initramfs virtio_console: Assure used length from device is limited virtio_net: Fix error handling in virtnet_restore() virtio-blk: Fix memory leak among suspend/resume procedure ACPI: video: Add quirk for the Dell Vostro 3350 ACPI: AMBA: Fix resource name in /proc/iomem pwm: tegra: Don't modify HW state in .remove callback power: supply: ab8500: add missing MODULE_DEVICE_TABLE power: supply: charger-manager: add missing MODULE_DEVICE_TABLE NFS: nfs_find_open_context() may only select open files ceph: remove bogus checks and WARN_ONs from ceph_set_page_dirty orangefs: fix orangefs df output. PCI: tegra: Add missing MODULE_DEVICE_TABLE x86/fpu: Return proper error codes from user access functions watchdog: iTCO_wdt: Account for rebooting on second timeout watchdog: Fix possible use-after-free by calling del_timer_sync() watchdog: sc520_wdt: Fix possible use-after-free in wdt_turnoff() watchdog: Fix possible use-after-free in wdt_startup() ARM: 9087/1: kprobes: test-thumb: fix for LLVM_IAS=1 power: reset: gpio-poweroff: add missing MODULE_DEVICE_TABLE power: supply: max17042: Do not enforce (incorrect) interrupt trigger type power: supply: ab8500: Avoid NULL pointers pwm: spear: Don't modify HW state in .remove callback lib/decompress_unlz4.c: correctly handle zero-padding around initrds. i2c: core: Disable client irq on reboot/shutdown intel_th: Wait until port is in reset before programming it staging: rtl8723bs: fix macro value for 2.4Ghz only device ALSA: hda: Add IRQ check for platform_get_irq() backlight: lm3630a: Fix return code of .update_status() callback powerpc/boot: Fixup device-tree on little endian usb: gadget: hid: fix error return code in hid_bind() usb: gadget: f_hid: fix endianness issue with descriptors ALSA: bebob: add support for ToneWeal FW66 Input: hideep - fix the uninitialized use in hideep_nvm_unlock() ASoC: soc-core: Fix the error return code in snd_soc_of_parse_audio_routing() gpio: pca953x: Add support for the On Semi pca9655 selftests/powerpc: Fix "no_handler" EBB selftest ALSA: ppc: fix error return code in snd_pmac_probe() gpio: zynq: Check return value of pm_runtime_get_sync powerpc/ps3: Add dma_mask to ps3_dma_region ALSA: sb: Fix potential double-free of CSP mixer elements selftests: timers: rtcpie: skip test if default RTC device does not exist s390/sclp_vt220: fix console name to match device mfd: da9052/stmpe: Add and modify MODULE_DEVICE_TABLE scsi: qedi: Fix null ref during abort handling scsi: iscsi: Fix shost->max_id use scsi: iscsi: Fix conn use after free during resets scsi: iscsi: Add iscsi_cls_conn refcount helpers fs/jfs: Fix missing error code in lmLogInit() scsi: scsi_dh_alua: Check for negative result value tty: serial: 8250: serial_cs: Fix a memory leak in error handling path ALSA: ac97: fix PM reference leak in ac97_bus_remove() scsi: core: Cap scsi_host cmd_per_lun at can_queue scsi: lpfc: Fix crash when lpfc_sli4_hba_setup() fails to initialize the SGLs scsi: lpfc: Fix "Unexpected timeout" error in direct attach topology w1: ds2438: fixing bug that would always get page0 Revert "ALSA: bebob/oxfw: fix Kconfig entry for Mackie d.2 Pro" misc/libmasm/module: Fix two use after free in ibmasm_init_one tty: serial: fsl_lpuart: fix the potential risk of division or modulo by zero PCI: aardvark: Fix kernel panic during PIO transfer PCI: aardvark: Don't rely on jiffies while holding spinlock tracing: Do not reference char * as a string in histograms scsi: core: Fix bad pointer dereference when ehandler kthread is invalid KVM: X86: Disable hardware breakpoints unconditionally before kvm_x86->run() KVM: x86: Use guest MAXPHYADDR from CPUID.0x8000_0008 iff TDP is enabled smackfs: restrict bytes count in smk_set_cipso() jfs: fix GPF in diFree pinctrl: mcp23s08: Fix missing unlock on error in mcp23s08_irq() media: uvcvideo: Fix pixel format change for Elgato Cam Link 4K media: gspca/sunplus: fix zero-length control requests media: gspca/sq905: fix control-request direction media: zr364xx: fix memory leak in zr364xx_start_readpipe media: dtv5100: fix control-request directions media: subdev: disallow ioctl for saa6588/davinci PCI: aardvark: Fix checking for PIO Non-posted Request PCI: Leave Apple Thunderbolt controllers on for s2idle or standby dm btree remove: assign new_root only when removal succeeds coresight: tmc-etf: Fix global-out-of-bounds in tmc_update_etf_buffer() ipack/carriers/tpci200: Fix a double free in tpci200_pci_probe tracing: Resize tgid_map to pid_max, not PID_MAX_DEFAULT tracing: Simplify & fix saved_tgids logic seq_buf: Fix overflow in seq_buf_putmem_hex() power: supply: ab8500: Fix an old bug ipmi/watchdog: Stop watchdog timer when the current action is 'none' qemu_fw_cfg: Make fw_cfg_rev_attr a proper kobj_attribute ASoC: tegra: Set driver_name=tegra for all machine drivers clocksource/arm_arch_timer: Improve Allwinner A64 timer workaround cpu/hotplug: Cure the cpusets trainwreck ata: ahci_sunxi: Disable DIPM mmc: core: Allow UHS-I voltage switch for SDSC cards if supported mmc: core: clear flags before allowing to retune mmc: sdhci: Fix warning message when accessing RPMB in HS400 mode drm/msm/mdp4: Fix modifier support enabling pinctrl/amd: Add device HID for new AMD GPIO controller drm/amd/display: fix incorrrect valid irq check drm/radeon: Add the missed drm_gem_object_put() in radeon_user_framebuffer_create() usb: gadget: f_fs: Fix setting of device and driver data cross-references powerpc/barrier: Avoid collision with clang's __lwsync macro fuse: reject internal errno serial: mvebu-uart: fix calculation of clock divisor serial: mvebu-uart: clarify the baud rate derivation bdi: Do not use freezable workqueue fscrypt: don't ignore minor_hash when hash is 0 MIPS: set mips32r5 for virt extensions sctp: add size validation when walking chunks sctp: validate from_addr_param return Bluetooth: btusb: fix bt fiwmare downloading failure issue for qca btsoc. Bluetooth: Shutdown controller after workqueues are flushed or cancelled Bluetooth: Fix the HCI to MGMT status conversion table RDMA/cma: Fix rdma_resolve_route() memory leak net: ip: avoid OOM kills with large UDP sends over loopback media, bpf: Do not copy more entries than user space requested wireless: wext-spy: Fix out-of-bounds warning sfc: error code if SRIOV cannot be disabled sfc: avoid double pci_remove of VFs iwlwifi: pcie: free IML DMA memory allocation iwlwifi: mvm: don't change band on bound PHY contexts RDMA/rxe: Don't overwrite errno from ib_umem_get() vsock: notify server to shutdown when client has pending signal atm: nicstar: register the interrupt handler in the right place atm: nicstar: use 'dma_free_coherent' instead of 'kfree' MIPS: add PMD table accounting into MIPS'pmd_alloc_one rtl8xxxu: Fix device info for RTL8192EU devices net: fix mistake path for netdev_features_strings cw1200: add missing MODULE_DEVICE_TABLE wl1251: Fix possible buffer overflow in wl1251_cmd_scan wlcore/wl12xx: Fix wl12xx get_mac error if device is in ELP xfrm: Fix error reporting in xfrm_state_construct. selinux: use __GFP_NOWARN with GFP_NOWAIT in the AVC fjes: check return value after calling platform_get_resource() net: micrel: check return value after calling platform_get_resource() net: mvpp2: check return value after calling platform_get_resource() net: bcmgenet: check return value after calling platform_get_resource() virtio_net: Remove BUG() to avoid machine dead ice: set the value of global config lock timeout longer pinctrl: mcp23s08: fix race condition in irq handler dm space maps: don't reset space map allocation cursor when committing RDMA/cxgb4: Fix missing error code in create_qp() ipv6: use prandom_u32() for ID generation clk: tegra: Ensure that PLLU configuration is applied properly clk: renesas: r8a77995: Add ZA2 clock e100: handle eeprom as little endian udf: Fix NULL pointer dereference in udf_symlink function drm/virtio: Fix double free on probe failure reiserfs: add check for invalid 1st journal block net: Treat __napi_schedule_irqoff() as __napi_schedule() on PREEMPT_RT atm: nicstar: Fix possible use-after-free in nicstar_cleanup() mISDN: fix possible use-after-free in HFC_cleanup() atm: iphase: fix possible use-after-free in ia_module_exit() hugetlb: clear huge pte during flush function on mips platform drm/amd/display: fix use_max_lb flag for 420 pixel formats net: pch_gbe: Use proper accessors to BE data in pch_ptp_match() drm/amd/amdgpu/sriov disable all ip hw status by default drm/zte: Don't select DRM_KMS_FB_HELPER drm/mxsfb: Don't select DRM_KMS_FB_HELPER mmc: vub3000: fix control-request direction mmc: block: Disable CMDQ on the ioctl path perf llvm: Return -ENOMEM when asprintf() fails selftests/vm/pkeys: fix alloc_random_pkey() to make it really, really random mm/huge_memory.c: don't discard hugepage if other processes are mapping it vfio/pci: Handle concurrent vma faults arm64: dts: marvell: armada-37xx: Fix reg for standard variant of UART serial: mvebu-uart: correctly calculate minimal possible baudrate powerpc: Offline CPU in stop_this_cpu() leds: ktd2692: Fix an error handling path leds: as3645a: Fix error return code in as3645a_parse_node() configfs: fix memleak in configfs_release_bin_file ASoC: atmel-i2s: Fix usage of capture and playback at the same time extcon: max8997: Add missing modalias string extcon: sm5502: Drop invalid register write in sm5502_reg_data phy: ti: dm816x: Fix the error handling path in 'dm816x_usb_phy_probe() scsi: mpt3sas: Fix error return value in _scsih_expander_add() mtd: rawnand: marvell: add missing clk_disable_unprepare() on error in marvell_nfc_resume() of: Fix truncation of memory sizes on 32-bit platforms ASoC: cs42l42: Correct definition of CS42L42_ADC_PDN_MASK iio: prox: isl29501: Fix buffer alignment in iio_push_to_buffers_with_timestamp() serial: 8250: Actually allow UPF_MAGIC_MULTIPLIER baud rates staging: mt7621-dts: fix pci address for PCI memory range staging: gdm724x: check for overflow in gdm_lte_netif_rx() staging: gdm724x: check for buffer overflow in gdm_lte_multi_sdu_pkt() iio: adc: ti-ads8688: Fix alignment of buffer in iio_push_to_buffers_with_timestamp() iio: adc: mxs-lradc: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: hx711: Fix buffer alignment in iio_push_to_buffers_with_timestamp() eeprom: idt_89hpesx: Restore printing the unsupported fwnode name eeprom: idt_89hpesx: Put fwnode in matching case during ->probe() s390: appldata depends on PROC_SYSCTL visorbus: fix error return code in visorchipset_init() fsi/sbefifo: Fix reset timeout fsi/sbefifo: Clean up correct FIFO when receiving reset request from SBE fsi: scom: Reset the FSI2PIB engine for any error fsi: core: Fix return of error values on failures scsi: FlashPoint: Rename si_flags field tty: nozomi: Fix the error handling path of 'nozomi_card_init()' char: pcmcia: error out if 'num_bytes_read' is greater than 4 in set_protocol() Input: hil_kbd - fix error return code in hil_dev_connect() ASoC: rsnd: tidyup loop on rsnd_adg_clk_query() ASoC: hisilicon: fix missing clk_disable_unprepare() on error in hi6210_i2s_startup() iio: potentiostat: lmp91000: Fix alignment of buffer in iio_push_to_buffers_with_timestamp() iio: light: tcs3472: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: light: tcs3414: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: light: isl29125: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: prox: as3935: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: prox: pulsed-light: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: prox: srf08: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: humidity: am2315: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: gyro: bmg160: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: vf610: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: ti-ads1015: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: stk8ba50: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: stk8312: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: kxcjk-1013: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: hid: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: bma220: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: bma180: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adis_buffer: do not return ints in irq handlers mwifiex: re-fix for unaligned accesses tty: nozomi: Fix a resource leak in an error handling function RDMA/mlx5: Don't access NULL-cleared mpi pointer net: sched: fix warning in tcindex_alloc_perfect_hash net: lwtunnel: handle MTU calculation in forwading writeback: fix obtain a reference to a freeing memcg css Bluetooth: Fix handling of HCI_LE_Advertising_Set_Terminated event Bluetooth: mgmt: Fix slab-out-of-bounds in tlv_data_is_valid ipv6: fix out-of-bound access in ip6_parse_tlv() ibmvnic: free tx_pool if tso_pool alloc fails Revert "ibmvnic: remove duplicate napi_schedule call in open function" i40e: Fix autoneg disabling for non-10GBaseT links i40e: Fix error handling in i40e_vsi_open bpf: Do not change gso_size during bpf_skb_change_proto() ipv6: exthdrs: do not blindly use init_net net: bcmgenet: Fix attaching to PYH failed on RPi 4B mac80211: remove iwlwifi specific workaround NDPs of null_response ieee802154: hwsim: avoid possible crash in hwsim_del_edge_nl() ieee802154: hwsim: Fix memory leak in hwsim_add_one net/ipv4: swap flow ports when validating source vxlan: add missing rcu_read_lock() in neigh_reduce() pkt_sched: sch_qfq: fix qfq_change_class() error path net: ethernet: ezchip: fix error handling net: ethernet: ezchip: fix UAF in nps_enet_remove net: ethernet: aeroflex: fix UAF in greth_of_remove samples/bpf: Fix the error return code of xdp_redirect's main() RDMA/rxe: Fix qp reference counting for atomic ops netfilter: nft_tproxy: restrict support to TCP and UDP transport protocols netfilter: nft_osf: check for TCP packet before further processing netfilter: nft_exthdr: check for IPv6 packet before further processing RDMA/mlx5: Don't add slave port to unaffiliated list netlabel: Fix memory leak in netlbl_mgmt_add_common ath10k: Fix an error code in ath10k_add_interface() brcmsmac: mac80211_if: Fix a resource leak in an error handling path brcmfmac: correctly report average RSSI in station info brcmfmac: fix setting of station info chains bitmask ssb: Fix error return code in ssb_bus_scan() wcn36xx: Move hal_buf allocation to devm_kmalloc in probe ieee802154: hwsim: Fix possible memory leak in hwsim_subscribe_all_others wireless: carl9170: fix LEDS build errors & warnings tools/bpftool: Fix error return code in do_batch() drm: qxl: ensure surf.data is ininitialized RDMA/rxe: Fix failure during driver load ehea: fix error return code in ehea_restart_qps() drm/rockchip: cdn-dp-core: add missing clk_disable_unprepare() on error in cdn_dp_grf_write() net: pch_gbe: Propagate error from devm_gpio_request_one() net: mvpp2: Put fwnode in error case during ->probe() ocfs2: fix snprintf() checking blk-wbt: make sure throttle is enabled properly blk-wbt: introduce a new disable state to prevent false positive by rwb_enabled() ACPI: sysfs: Fix a buffer overrun problem with description_show() crypto: nx - Fix RCU warning in nx842_OF_upd_status spi: spi-sun6i: Fix chipselect/clock bug btrfs: clear log tree recovering status if starting transaction fails hwmon: (max31790) Fix fan speed reporting for fan7..12 hwmon: (max31722) Remove non-standard ACPI device IDs media: s5p-g2d: Fix a memory leak on ctx->fh.m2m_ctx mmc: usdhi6rol0: fix error return code in usdhi6_probe() media: siano: Fix out-of-bounds warnings in smscore_load_firmware_family2() media: gspca/gl860: fix zero-length control requests media: tc358743: Fix error return code in tc358743_probe_of() media: exynos4-is: Fix a use after free in isp_video_release pata_ep93xx: fix deferred probing media: rc: i2c: Fix an error message crypto: ccp - Fix a resource leak in an error handling path evm: fix writing <securityfs>/evm overflow pata_octeon_cf: avoid WARN_ON() in ata_host_activate() media: I2C: change 'RST' to "RSET" to fix multiple build errors pata_rb532_cf: fix deferred probing sata_highbank: fix deferred probing crypto: ux500 - Fix error return code in hash_hw_final() crypto: ixp4xx - dma_unmap the correct address media: s5p_cec: decrement usage count if disabled ia64: mca_drv: fix incorrect array size calculation HID: wacom: Correct base usage for capacitive ExpressKey status bits ACPI: tables: Add custom DSDT file as makefile prerequisite clocksource: Retry clock read if long delays detected platform/x86: toshiba_acpi: Fix missing error code in toshiba_acpi_setup_keyboard() ACPI: bus: Call kobject_put() in acpi_init() error path ACPICA: Fix memory leak caused by _CID repair function fs: dlm: fix memory leak when fenced random32: Fix implicit truncation warning in prandom_seed_state() fs: dlm: cancel work sync othercon block_dump: remove block_dump feature in mark_inode_dirty() ACPI: EC: Make more Asus laptops use ECDT _GPE lib: vsprintf: Fix handling of number field widths in vsscanf hv_utils: Fix passing zero to 'PTR_ERR' warning ACPI: processor idle: Fix up C-state latency if not ordered EDAC/ti: Add missing MODULE_DEVICE_TABLE HID: do not use down_interruptible() when unbinding devices regulator: da9052: Ensure enough delay time for .set_voltage_time_sel btrfs: disable build on platforms having page size 256K btrfs: abort transaction if we fail to update the delayed inode btrfs: fix error handling in __btrfs_update_delayed_inode media: imx-csi: Skip first few frames from a BT.656 source media: siano: fix device register error path media: dvb_net: avoid speculation from net slot crypto: shash - avoid comparing pointers to exported functions under CFI mmc: via-sdmmc: add a check against NULL pointer dereference media: dvd_usb: memory leak in cinergyt2_fe_attach media: st-hva: Fix potential NULL pointer dereferences media: bt8xx: Fix a missing check bug in bt878_probe media: v4l2-core: Avoid the dangling pointer in v4l2_fh_release media: em28xx: Fix possible memory leak of em28xx struct sched/fair: Fix ascii art by relpacing tabs crypto: qat - remove unused macro in FW loader crypto: qat - check return code of qat_hal_rd_rel_reg() media: pvrusb2: fix warning in pvr2_i2c_core_done media: cobalt: fix race condition in setting HPD media: cpia2: fix memory leak in cpia2_usb_probe crypto: nx - add missing MODULE_DEVICE_TABLE regulator: uniphier: Add missing MODULE_DEVICE_TABLE spi: omap-100k: Fix the length judgment problem spi: spi-topcliff-pch: Fix potential double free in pch_spi_process_messages() spi: spi-loopback-test: Fix 'tx_buf' might be 'rx_buf' spi: Make of_register_spi_device also set the fwnode fuse: check connected before queueing on fpq->io evm: Refuse EVM_ALLOW_METADATA_WRITES only if an HMAC key is loaded evm: Execute evm_inode_init_security() only when an HMAC key is loaded powerpc/stacktrace: Fix spurious "stale" traces in raise_backtrace_ipi() seq_buf: Make trace_seq_putmem_hex() support data longer than 8 tracepoint: Add tracepoint_probe_register_may_exist() for BPF tracing tracing/histograms: Fix parsing of "sym-offset" modifier rsi: fix AP mode with WPA failure due to encrypted EAPOL rsi: Assign beacon rate settings to the correct rate_info descriptor field ssb: sdio: Don't overwrite const buffer if block_write fails ath9k: Fix kernel NULL pointer dereference during ath_reset_internal() serial_cs: remove wrong GLOBETROTTER.cis entry serial_cs: Add Option International GSM-Ready 56K/ISDN modem serial: sh-sci: Stop dmaengine transfer in sci_stop_tx() iio: ltr501: ltr501_read_ps(): add missing endianness conversion iio: ltr501: ltr559: fix initialization of LTR501_ALS_CONTR iio: ltr501: mark register holding upper 8 bits of ALS_DATA{0,1} and PS_DATA as volatile, too iio: light: tcs3472: do not free unallocated IRQ rtc: stm32: Fix unbalanced clk_disable_unprepare() on probe error path s390/cio: dont call css_wait_for_slow_path() inside a lock SUNRPC: Should wake up the privileged task firstly. SUNRPC: Fix the batch tasks count wraparound. can: peak_pciefd: pucan_handle_status(): fix a potential starvation issue in TX path can: gw: synchronize rcu operations before removing gw job entry can: bcm: delay release of struct bcm_op after synchronize_rcu() ext4: use ext4_grp_locked_error in mb_find_extent ext4: fix avefreec in find_group_orlov ext4: remove check for zero nr_to_scan in ext4_es_scan() ext4: correct the cache_nr in tracepoint ext4_es_shrink_exit ext4: return error code when ext4_fill_flex_info() fails ext4: fix kernel infoleak via ext4_extent_header ext4: cleanup in-core orphan list if ext4_truncate() failed to get a transaction handle btrfs: clear defrag status of a root if starting transaction fails btrfs: send: fix invalid path for unlink operations after parent orphanization ARM: dts: at91: sama5d4: fix pinctrl muxing arm_pmu: Fix write counter incorrect in ARMv7 big-endian mode Input: joydev - prevent use of not validated data in JSIOCSBTNMAP ioctl iov_iter_fault_in_readable() should do nothing in xarray case ntfs: fix validity check for file name attribute xhci: solve a double free problem while doing s4 usb: typec: Add the missed altmode_id_remove() in typec_register_altmode() usb: dwc3: Fix debugfs creation flow USB: cdc-acm: blacklist Heimann USB Appset device usb: gadget: eem: fix echo command packet response issue net: can: ems_usb: fix use-after-free in ems_usb_disconnect() Input: usbtouchscreen - fix control-request directions media: dvb-usb: fix wrong definition ALSA: usb-audio: Fix OOB access at proc output ALSA: usb-audio: fix rate on Ozone Z90 USB headset scsi: core: Retry I/O for Notify (Enable Spinup) Required error Revert "clocksource/drivers/timer-ti-dm: Handle dra7 timer wrap errata i940" Linux 4.19.197 clocksource/drivers/timer-ti-dm: Handle dra7 timer wrap errata i940 clocksource/drivers/timer-ti-dm: Prepare to handle dra7 timer wrap issue clocksource/drivers/timer-ti-dm: Add clockevent and clocksource support ARM: OMAP: replace setup_irq() by request_irq() KVM: SVM: Call SEV Guest Decommission if ASID binding fails xen/events: reset active flag for lateeoi events later kthread: prevent deadlock when kthread_mod_delayed_work() races with kthread_cancel_delayed_work_sync() kthread_worker: split code for canceling the delayed work timer ARM: dts: imx6qdl-sabresd: Remove incorrect power supply assignment KVM: SVM: Periodically schedule when unregistering regions on destroy ext4: eliminate bogus error in ext4_data_block_valid_rcu() drm/nouveau: fix dma_address check for CPU/GPU sync scsi: sr: Return appropriate error code when disk is ejected mm, futex: fix shared futex pgoff on shmem huge page mm/thp: another PVMW_SYNC fix in page_vma_mapped_walk() mm/thp: fix page_vma_mapped_walk() if THP mapped by ptes mm: page_vma_mapped_walk(): get vma_address_end() earlier mm: page_vma_mapped_walk(): use goto instead of while (1) mm: page_vma_mapped_walk(): add a level of indentation mm: page_vma_mapped_walk(): crossing page table boundary mm: page_vma_mapped_walk(): prettify PVMW_MIGRATION block mm: page_vma_mapped_walk(): use pmde for *pvmw->pmd mm: page_vma_mapped_walk(): settle PageHuge on entry mm: page_vma_mapped_walk(): use page for pvmw->page mm: thp: replace DEBUG_VM BUG with VM_WARN when unmap fails for split mm/thp: unmap_mapping_page() to fix THP truncate_cleanup_page() mm/thp: fix page_address_in_vma() on file THP tails mm/thp: fix vma_address() if virtual address below file offset mm/thp: try_to_unmap() use TTU_SYNC for safe splitting mm/thp: make is_huge_zero_pmd() safe and quicker mm/thp: fix __split_huge_pmd_locked() on shmem migration entry mm/rmap: use page_not_mapped in try_to_unmap() mm/rmap: remove unneeded semicolon in page_not_mapped() mm: add VM_WARN_ON_ONCE_PAGE() macro Change-Id: Ia9b845672bf98427007fcdb455a467e602cfcd29 Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com> Conflicts: drivers/staging/android/ion/ion.c drivers/usb/dwc3/core.c drivers/usb/gadget/function/f_fs.c kernel/cpu.c security/selinux/avc.c
1239 lines
32 KiB
C
1239 lines
32 KiB
C
/*
|
|
* Implementation of the kernel access vector cache (AVC).
|
|
*
|
|
* Authors: Stephen Smalley, <sds@tycho.nsa.gov>
|
|
* James Morris <jmorris@redhat.com>
|
|
*
|
|
* Update: KaiGai, Kohei <kaigai@ak.jp.nec.com>
|
|
* Replaced the avc_lock spinlock by RCU.
|
|
*
|
|
* Copyright (C) 2003 Red Hat, Inc., James Morris <jmorris@redhat.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2,
|
|
* as published by the Free Software Foundation.
|
|
*/
|
|
#include <linux/types.h>
|
|
#include <linux/stddef.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/dcache.h>
|
|
#include <linux/init.h>
|
|
#include <linux/skbuff.h>
|
|
#include <linux/percpu.h>
|
|
#include <linux/list.h>
|
|
#include <net/sock.h>
|
|
#include <linux/un.h>
|
|
#include <net/af_unix.h>
|
|
#include <linux/ip.h>
|
|
#include <linux/audit.h>
|
|
#include <linux/ipv6.h>
|
|
#include <net/ipv6.h>
|
|
#include "avc.h"
|
|
#include "avc_ss.h"
|
|
#include "classmap.h"
|
|
|
|
#define AVC_CACHE_SLOTS 512
|
|
#define AVC_DEF_CACHE_THRESHOLD 512
|
|
#define AVC_CACHE_RECLAIM 16
|
|
|
|
#ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
|
|
#define avc_cache_stats_incr(field) this_cpu_inc(avc_cache_stats.field)
|
|
#else
|
|
#define avc_cache_stats_incr(field) do {} while (0)
|
|
#endif
|
|
|
|
struct avc_entry {
|
|
u32 ssid;
|
|
u32 tsid;
|
|
u16 tclass;
|
|
struct av_decision avd;
|
|
struct avc_xperms_node *xp_node;
|
|
};
|
|
|
|
struct avc_node {
|
|
struct avc_entry ae;
|
|
struct hlist_node list; /* anchored in avc_cache->slots[i] */
|
|
struct rcu_head rhead;
|
|
};
|
|
|
|
struct avc_xperms_decision_node {
|
|
struct extended_perms_decision xpd;
|
|
struct list_head xpd_list; /* list of extended_perms_decision */
|
|
};
|
|
|
|
struct avc_xperms_node {
|
|
struct extended_perms xp;
|
|
struct list_head xpd_head; /* list head of extended_perms_decision */
|
|
};
|
|
|
|
struct avc_cache {
|
|
struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
|
|
spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
|
|
atomic_t lru_hint; /* LRU hint for reclaim scan */
|
|
atomic_t active_nodes;
|
|
u32 latest_notif; /* latest revocation notification */
|
|
};
|
|
|
|
struct avc_callback_node {
|
|
int (*callback) (u32 event);
|
|
u32 events;
|
|
struct avc_callback_node *next;
|
|
};
|
|
|
|
#ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
|
|
DEFINE_PER_CPU(struct avc_cache_stats, avc_cache_stats) = { 0 };
|
|
#endif
|
|
|
|
struct selinux_avc {
|
|
unsigned int avc_cache_threshold;
|
|
struct avc_cache avc_cache;
|
|
};
|
|
|
|
static struct selinux_avc selinux_avc;
|
|
|
|
void selinux_avc_init(struct selinux_avc **avc)
|
|
{
|
|
int i;
|
|
|
|
selinux_avc.avc_cache_threshold = AVC_DEF_CACHE_THRESHOLD;
|
|
for (i = 0; i < AVC_CACHE_SLOTS; i++) {
|
|
INIT_HLIST_HEAD(&selinux_avc.avc_cache.slots[i]);
|
|
spin_lock_init(&selinux_avc.avc_cache.slots_lock[i]);
|
|
}
|
|
atomic_set(&selinux_avc.avc_cache.active_nodes, 0);
|
|
atomic_set(&selinux_avc.avc_cache.lru_hint, 0);
|
|
*avc = &selinux_avc;
|
|
}
|
|
|
|
unsigned int avc_get_cache_threshold(struct selinux_avc *avc)
|
|
{
|
|
return avc->avc_cache_threshold;
|
|
}
|
|
|
|
void avc_set_cache_threshold(struct selinux_avc *avc,
|
|
unsigned int cache_threshold)
|
|
{
|
|
avc->avc_cache_threshold = cache_threshold;
|
|
}
|
|
|
|
static struct avc_callback_node *avc_callbacks;
|
|
static struct kmem_cache *avc_node_cachep;
|
|
static struct kmem_cache *avc_xperms_data_cachep;
|
|
static struct kmem_cache *avc_xperms_decision_cachep;
|
|
static struct kmem_cache *avc_xperms_cachep;
|
|
|
|
static inline int avc_hash(u32 ssid, u32 tsid, u16 tclass)
|
|
{
|
|
return (ssid ^ (tsid<<2) ^ (tclass<<4)) & (AVC_CACHE_SLOTS - 1);
|
|
}
|
|
|
|
/**
|
|
* avc_dump_av - Display an access vector in human-readable form.
|
|
* @tclass: target security class
|
|
* @av: access vector
|
|
*/
|
|
static void avc_dump_av(struct audit_buffer *ab, u16 tclass, u32 av)
|
|
{
|
|
const char **perms;
|
|
int i, perm;
|
|
|
|
if (av == 0) {
|
|
audit_log_format(ab, " null");
|
|
return;
|
|
}
|
|
|
|
BUG_ON(!tclass || tclass >= ARRAY_SIZE(secclass_map));
|
|
perms = secclass_map[tclass-1].perms;
|
|
|
|
audit_log_format(ab, " {");
|
|
i = 0;
|
|
perm = 1;
|
|
while (i < (sizeof(av) * 8)) {
|
|
if ((perm & av) && perms[i]) {
|
|
audit_log_format(ab, " %s", perms[i]);
|
|
av &= ~perm;
|
|
}
|
|
i++;
|
|
perm <<= 1;
|
|
}
|
|
|
|
if (av)
|
|
audit_log_format(ab, " 0x%x", av);
|
|
|
|
audit_log_format(ab, " }");
|
|
}
|
|
|
|
/**
|
|
* avc_dump_query - Display a SID pair and a class in human-readable form.
|
|
* @ssid: source security identifier
|
|
* @tsid: target security identifier
|
|
* @tclass: target security class
|
|
*/
|
|
static void avc_dump_query(struct audit_buffer *ab, struct selinux_state *state,
|
|
u32 ssid, u32 tsid, u16 tclass)
|
|
{
|
|
int rc;
|
|
char *scontext;
|
|
u32 scontext_len;
|
|
|
|
rc = security_sid_to_context(state, ssid, &scontext, &scontext_len);
|
|
if (rc)
|
|
audit_log_format(ab, "ssid=%d", ssid);
|
|
else {
|
|
audit_log_format(ab, "scontext=%s", scontext);
|
|
kfree(scontext);
|
|
}
|
|
|
|
rc = security_sid_to_context(state, tsid, &scontext, &scontext_len);
|
|
if (rc)
|
|
audit_log_format(ab, " tsid=%d", tsid);
|
|
else {
|
|
audit_log_format(ab, " tcontext=%s", scontext);
|
|
kfree(scontext);
|
|
}
|
|
|
|
BUG_ON(!tclass || tclass >= ARRAY_SIZE(secclass_map));
|
|
audit_log_format(ab, " tclass=%s", secclass_map[tclass-1].name);
|
|
}
|
|
|
|
/**
|
|
* avc_init - Initialize the AVC.
|
|
*
|
|
* Initialize the access vector cache.
|
|
*/
|
|
void __init avc_init(void)
|
|
{
|
|
avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
|
|
0, SLAB_PANIC, NULL);
|
|
avc_xperms_cachep = kmem_cache_create("avc_xperms_node",
|
|
sizeof(struct avc_xperms_node),
|
|
0, SLAB_PANIC, NULL);
|
|
avc_xperms_decision_cachep = kmem_cache_create(
|
|
"avc_xperms_decision_node",
|
|
sizeof(struct avc_xperms_decision_node),
|
|
0, SLAB_PANIC, NULL);
|
|
avc_xperms_data_cachep = kmem_cache_create("avc_xperms_data",
|
|
sizeof(struct extended_perms_data),
|
|
0, SLAB_PANIC, NULL);
|
|
}
|
|
|
|
int avc_get_hash_stats(struct selinux_avc *avc, char *page)
|
|
{
|
|
int i, chain_len, max_chain_len, slots_used;
|
|
struct avc_node *node;
|
|
struct hlist_head *head;
|
|
|
|
rcu_read_lock();
|
|
|
|
slots_used = 0;
|
|
max_chain_len = 0;
|
|
for (i = 0; i < AVC_CACHE_SLOTS; i++) {
|
|
head = &avc->avc_cache.slots[i];
|
|
if (!hlist_empty(head)) {
|
|
slots_used++;
|
|
chain_len = 0;
|
|
hlist_for_each_entry_rcu(node, head, list)
|
|
chain_len++;
|
|
if (chain_len > max_chain_len)
|
|
max_chain_len = chain_len;
|
|
}
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
return scnprintf(page, PAGE_SIZE, "entries: %d\nbuckets used: %d/%d\n"
|
|
"longest chain: %d\n",
|
|
atomic_read(&avc->avc_cache.active_nodes),
|
|
slots_used, AVC_CACHE_SLOTS, max_chain_len);
|
|
}
|
|
|
|
/*
|
|
* using a linked list for extended_perms_decision lookup because the list is
|
|
* always small. i.e. less than 5, typically 1
|
|
*/
|
|
static struct extended_perms_decision *avc_xperms_decision_lookup(u8 driver,
|
|
struct avc_xperms_node *xp_node)
|
|
{
|
|
struct avc_xperms_decision_node *xpd_node;
|
|
|
|
list_for_each_entry(xpd_node, &xp_node->xpd_head, xpd_list) {
|
|
if (xpd_node->xpd.driver == driver)
|
|
return &xpd_node->xpd;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static inline unsigned int
|
|
avc_xperms_has_perm(struct extended_perms_decision *xpd,
|
|
u8 perm, u8 which)
|
|
{
|
|
unsigned int rc = 0;
|
|
|
|
if ((which == XPERMS_ALLOWED) &&
|
|
(xpd->used & XPERMS_ALLOWED))
|
|
rc = security_xperm_test(xpd->allowed->p, perm);
|
|
else if ((which == XPERMS_AUDITALLOW) &&
|
|
(xpd->used & XPERMS_AUDITALLOW))
|
|
rc = security_xperm_test(xpd->auditallow->p, perm);
|
|
else if ((which == XPERMS_DONTAUDIT) &&
|
|
(xpd->used & XPERMS_DONTAUDIT))
|
|
rc = security_xperm_test(xpd->dontaudit->p, perm);
|
|
return rc;
|
|
}
|
|
|
|
static void avc_xperms_allow_perm(struct avc_xperms_node *xp_node,
|
|
u8 driver, u8 perm)
|
|
{
|
|
struct extended_perms_decision *xpd;
|
|
security_xperm_set(xp_node->xp.drivers.p, driver);
|
|
xpd = avc_xperms_decision_lookup(driver, xp_node);
|
|
if (xpd && xpd->allowed)
|
|
security_xperm_set(xpd->allowed->p, perm);
|
|
}
|
|
|
|
static void avc_xperms_decision_free(struct avc_xperms_decision_node *xpd_node)
|
|
{
|
|
struct extended_perms_decision *xpd;
|
|
|
|
xpd = &xpd_node->xpd;
|
|
if (xpd->allowed)
|
|
kmem_cache_free(avc_xperms_data_cachep, xpd->allowed);
|
|
if (xpd->auditallow)
|
|
kmem_cache_free(avc_xperms_data_cachep, xpd->auditallow);
|
|
if (xpd->dontaudit)
|
|
kmem_cache_free(avc_xperms_data_cachep, xpd->dontaudit);
|
|
kmem_cache_free(avc_xperms_decision_cachep, xpd_node);
|
|
}
|
|
|
|
static void avc_xperms_free(struct avc_xperms_node *xp_node)
|
|
{
|
|
struct avc_xperms_decision_node *xpd_node, *tmp;
|
|
|
|
if (!xp_node)
|
|
return;
|
|
|
|
list_for_each_entry_safe(xpd_node, tmp, &xp_node->xpd_head, xpd_list) {
|
|
list_del(&xpd_node->xpd_list);
|
|
avc_xperms_decision_free(xpd_node);
|
|
}
|
|
kmem_cache_free(avc_xperms_cachep, xp_node);
|
|
}
|
|
|
|
static void avc_copy_xperms_decision(struct extended_perms_decision *dest,
|
|
struct extended_perms_decision *src)
|
|
{
|
|
dest->driver = src->driver;
|
|
dest->used = src->used;
|
|
if (dest->used & XPERMS_ALLOWED)
|
|
memcpy(dest->allowed->p, src->allowed->p,
|
|
sizeof(src->allowed->p));
|
|
if (dest->used & XPERMS_AUDITALLOW)
|
|
memcpy(dest->auditallow->p, src->auditallow->p,
|
|
sizeof(src->auditallow->p));
|
|
if (dest->used & XPERMS_DONTAUDIT)
|
|
memcpy(dest->dontaudit->p, src->dontaudit->p,
|
|
sizeof(src->dontaudit->p));
|
|
}
|
|
|
|
/*
|
|
* similar to avc_copy_xperms_decision, but only copy decision
|
|
* information relevant to this perm
|
|
*/
|
|
static inline void avc_quick_copy_xperms_decision(u8 perm,
|
|
struct extended_perms_decision *dest,
|
|
struct extended_perms_decision *src)
|
|
{
|
|
/*
|
|
* compute index of the u32 of the 256 bits (8 u32s) that contain this
|
|
* command permission
|
|
*/
|
|
u8 i = perm >> 5;
|
|
|
|
dest->used = src->used;
|
|
if (dest->used & XPERMS_ALLOWED)
|
|
dest->allowed->p[i] = src->allowed->p[i];
|
|
if (dest->used & XPERMS_AUDITALLOW)
|
|
dest->auditallow->p[i] = src->auditallow->p[i];
|
|
if (dest->used & XPERMS_DONTAUDIT)
|
|
dest->dontaudit->p[i] = src->dontaudit->p[i];
|
|
}
|
|
|
|
static struct avc_xperms_decision_node
|
|
*avc_xperms_decision_alloc(u8 which)
|
|
{
|
|
struct avc_xperms_decision_node *xpd_node;
|
|
struct extended_perms_decision *xpd;
|
|
|
|
xpd_node = kmem_cache_zalloc(avc_xperms_decision_cachep,
|
|
GFP_NOWAIT | __GFP_NOWARN);
|
|
if (!xpd_node)
|
|
return NULL;
|
|
|
|
xpd = &xpd_node->xpd;
|
|
if (which & XPERMS_ALLOWED) {
|
|
xpd->allowed = kmem_cache_zalloc(avc_xperms_data_cachep,
|
|
GFP_NOWAIT | __GFP_NOWARN);
|
|
if (!xpd->allowed)
|
|
goto error;
|
|
}
|
|
if (which & XPERMS_AUDITALLOW) {
|
|
xpd->auditallow = kmem_cache_zalloc(avc_xperms_data_cachep,
|
|
GFP_NOWAIT | __GFP_NOWARN);
|
|
if (!xpd->auditallow)
|
|
goto error;
|
|
}
|
|
if (which & XPERMS_DONTAUDIT) {
|
|
xpd->dontaudit = kmem_cache_zalloc(avc_xperms_data_cachep,
|
|
GFP_NOWAIT | __GFP_NOWARN);
|
|
if (!xpd->dontaudit)
|
|
goto error;
|
|
}
|
|
return xpd_node;
|
|
error:
|
|
avc_xperms_decision_free(xpd_node);
|
|
return NULL;
|
|
}
|
|
|
|
static int avc_add_xperms_decision(struct avc_node *node,
|
|
struct extended_perms_decision *src)
|
|
{
|
|
struct avc_xperms_decision_node *dest_xpd;
|
|
|
|
node->ae.xp_node->xp.len++;
|
|
dest_xpd = avc_xperms_decision_alloc(src->used);
|
|
if (!dest_xpd)
|
|
return -ENOMEM;
|
|
avc_copy_xperms_decision(&dest_xpd->xpd, src);
|
|
list_add(&dest_xpd->xpd_list, &node->ae.xp_node->xpd_head);
|
|
return 0;
|
|
}
|
|
|
|
static struct avc_xperms_node *avc_xperms_alloc(void)
|
|
{
|
|
struct avc_xperms_node *xp_node;
|
|
|
|
xp_node = kmem_cache_zalloc(avc_xperms_cachep, GFP_NOWAIT | __GFP_NOWARN);
|
|
if (!xp_node)
|
|
return xp_node;
|
|
INIT_LIST_HEAD(&xp_node->xpd_head);
|
|
return xp_node;
|
|
}
|
|
|
|
static int avc_xperms_populate(struct avc_node *node,
|
|
struct avc_xperms_node *src)
|
|
{
|
|
struct avc_xperms_node *dest;
|
|
struct avc_xperms_decision_node *dest_xpd;
|
|
struct avc_xperms_decision_node *src_xpd;
|
|
|
|
if (src->xp.len == 0)
|
|
return 0;
|
|
dest = avc_xperms_alloc();
|
|
if (!dest)
|
|
return -ENOMEM;
|
|
|
|
memcpy(dest->xp.drivers.p, src->xp.drivers.p, sizeof(dest->xp.drivers.p));
|
|
dest->xp.len = src->xp.len;
|
|
|
|
/* for each source xpd allocate a destination xpd and copy */
|
|
list_for_each_entry(src_xpd, &src->xpd_head, xpd_list) {
|
|
dest_xpd = avc_xperms_decision_alloc(src_xpd->xpd.used);
|
|
if (!dest_xpd)
|
|
goto error;
|
|
avc_copy_xperms_decision(&dest_xpd->xpd, &src_xpd->xpd);
|
|
list_add(&dest_xpd->xpd_list, &dest->xpd_head);
|
|
}
|
|
node->ae.xp_node = dest;
|
|
return 0;
|
|
error:
|
|
avc_xperms_free(dest);
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
static inline u32 avc_xperms_audit_required(u32 requested,
|
|
struct av_decision *avd,
|
|
struct extended_perms_decision *xpd,
|
|
u8 perm,
|
|
int result,
|
|
u32 *deniedp)
|
|
{
|
|
u32 denied, audited;
|
|
|
|
denied = requested & ~avd->allowed;
|
|
if (unlikely(denied)) {
|
|
audited = denied & avd->auditdeny;
|
|
if (audited && xpd) {
|
|
if (avc_xperms_has_perm(xpd, perm, XPERMS_DONTAUDIT))
|
|
audited &= ~requested;
|
|
}
|
|
} else if (result) {
|
|
audited = denied = requested;
|
|
} else {
|
|
audited = requested & avd->auditallow;
|
|
if (audited && xpd) {
|
|
if (!avc_xperms_has_perm(xpd, perm, XPERMS_AUDITALLOW))
|
|
audited &= ~requested;
|
|
}
|
|
}
|
|
|
|
*deniedp = denied;
|
|
return audited;
|
|
}
|
|
|
|
static inline int avc_xperms_audit(struct selinux_state *state,
|
|
u32 ssid, u32 tsid, u16 tclass,
|
|
u32 requested, struct av_decision *avd,
|
|
struct extended_perms_decision *xpd,
|
|
u8 perm, int result,
|
|
struct common_audit_data *ad)
|
|
{
|
|
u32 audited, denied;
|
|
|
|
audited = avc_xperms_audit_required(
|
|
requested, avd, xpd, perm, result, &denied);
|
|
if (likely(!audited))
|
|
return 0;
|
|
return slow_avc_audit(state, ssid, tsid, tclass, requested,
|
|
audited, denied, result, ad);
|
|
}
|
|
|
|
static void avc_node_free(struct rcu_head *rhead)
|
|
{
|
|
struct avc_node *node = container_of(rhead, struct avc_node, rhead);
|
|
avc_xperms_free(node->ae.xp_node);
|
|
kmem_cache_free(avc_node_cachep, node);
|
|
avc_cache_stats_incr(frees);
|
|
}
|
|
|
|
static void avc_node_delete(struct selinux_avc *avc, struct avc_node *node)
|
|
{
|
|
hlist_del_rcu(&node->list);
|
|
call_rcu(&node->rhead, avc_node_free);
|
|
atomic_dec(&avc->avc_cache.active_nodes);
|
|
}
|
|
|
|
static void avc_node_kill(struct selinux_avc *avc, struct avc_node *node)
|
|
{
|
|
avc_xperms_free(node->ae.xp_node);
|
|
kmem_cache_free(avc_node_cachep, node);
|
|
avc_cache_stats_incr(frees);
|
|
atomic_dec(&avc->avc_cache.active_nodes);
|
|
}
|
|
|
|
static void avc_node_replace(struct selinux_avc *avc,
|
|
struct avc_node *new, struct avc_node *old)
|
|
{
|
|
hlist_replace_rcu(&old->list, &new->list);
|
|
call_rcu(&old->rhead, avc_node_free);
|
|
atomic_dec(&avc->avc_cache.active_nodes);
|
|
}
|
|
|
|
static inline int avc_reclaim_node(struct selinux_avc *avc)
|
|
{
|
|
struct avc_node *node;
|
|
int hvalue, try, ecx;
|
|
unsigned long flags;
|
|
struct hlist_head *head;
|
|
spinlock_t *lock;
|
|
|
|
for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
|
|
hvalue = atomic_inc_return(&avc->avc_cache.lru_hint) &
|
|
(AVC_CACHE_SLOTS - 1);
|
|
head = &avc->avc_cache.slots[hvalue];
|
|
lock = &avc->avc_cache.slots_lock[hvalue];
|
|
|
|
if (!spin_trylock_irqsave(lock, flags))
|
|
continue;
|
|
|
|
rcu_read_lock();
|
|
hlist_for_each_entry(node, head, list) {
|
|
avc_node_delete(avc, node);
|
|
avc_cache_stats_incr(reclaims);
|
|
ecx++;
|
|
if (ecx >= AVC_CACHE_RECLAIM) {
|
|
rcu_read_unlock();
|
|
spin_unlock_irqrestore(lock, flags);
|
|
goto out;
|
|
}
|
|
}
|
|
rcu_read_unlock();
|
|
spin_unlock_irqrestore(lock, flags);
|
|
}
|
|
out:
|
|
return ecx;
|
|
}
|
|
|
|
static struct avc_node *avc_alloc_node(struct selinux_avc *avc)
|
|
{
|
|
struct avc_node *node;
|
|
|
|
node = kmem_cache_zalloc(avc_node_cachep, GFP_NOWAIT | __GFP_NOWARN);
|
|
if (!node)
|
|
goto out;
|
|
|
|
INIT_HLIST_NODE(&node->list);
|
|
avc_cache_stats_incr(allocations);
|
|
|
|
if (atomic_inc_return(&avc->avc_cache.active_nodes) >
|
|
avc->avc_cache_threshold)
|
|
avc_reclaim_node(avc);
|
|
|
|
out:
|
|
return node;
|
|
}
|
|
|
|
static void avc_node_populate(struct avc_node *node, u32 ssid, u32 tsid, u16 tclass, struct av_decision *avd)
|
|
{
|
|
node->ae.ssid = ssid;
|
|
node->ae.tsid = tsid;
|
|
node->ae.tclass = tclass;
|
|
memcpy(&node->ae.avd, avd, sizeof(node->ae.avd));
|
|
}
|
|
|
|
static inline struct avc_node *avc_search_node(struct selinux_avc *avc,
|
|
u32 ssid, u32 tsid, u16 tclass)
|
|
{
|
|
struct avc_node *node, *ret = NULL;
|
|
int hvalue;
|
|
struct hlist_head *head;
|
|
|
|
hvalue = avc_hash(ssid, tsid, tclass);
|
|
head = &avc->avc_cache.slots[hvalue];
|
|
hlist_for_each_entry_rcu(node, head, list) {
|
|
if (ssid == node->ae.ssid &&
|
|
tclass == node->ae.tclass &&
|
|
tsid == node->ae.tsid) {
|
|
ret = node;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* avc_lookup - Look up an AVC entry.
|
|
* @ssid: source security identifier
|
|
* @tsid: target security identifier
|
|
* @tclass: target security class
|
|
*
|
|
* Look up an AVC entry that is valid for the
|
|
* (@ssid, @tsid), interpreting the permissions
|
|
* based on @tclass. If a valid AVC entry exists,
|
|
* then this function returns the avc_node.
|
|
* Otherwise, this function returns NULL.
|
|
*/
|
|
static struct avc_node *avc_lookup(struct selinux_avc *avc,
|
|
u32 ssid, u32 tsid, u16 tclass)
|
|
{
|
|
struct avc_node *node;
|
|
|
|
avc_cache_stats_incr(lookups);
|
|
node = avc_search_node(avc, ssid, tsid, tclass);
|
|
|
|
if (node)
|
|
return node;
|
|
|
|
avc_cache_stats_incr(misses);
|
|
return NULL;
|
|
}
|
|
|
|
static int avc_latest_notif_update(struct selinux_avc *avc,
|
|
int seqno, int is_insert)
|
|
{
|
|
int ret = 0;
|
|
static DEFINE_SPINLOCK(notif_lock);
|
|
unsigned long flag;
|
|
|
|
spin_lock_irqsave(¬if_lock, flag);
|
|
if (is_insert) {
|
|
if (seqno < avc->avc_cache.latest_notif) {
|
|
pr_warn("SELinux: avc: seqno %d < latest_notif %d\n",
|
|
seqno, avc->avc_cache.latest_notif);
|
|
ret = -EAGAIN;
|
|
}
|
|
} else {
|
|
if (seqno > avc->avc_cache.latest_notif)
|
|
avc->avc_cache.latest_notif = seqno;
|
|
}
|
|
spin_unlock_irqrestore(¬if_lock, flag);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* avc_insert - Insert an AVC entry.
|
|
* @ssid: source security identifier
|
|
* @tsid: target security identifier
|
|
* @tclass: target security class
|
|
* @avd: resulting av decision
|
|
* @xp_node: resulting extended permissions
|
|
*
|
|
* Insert an AVC entry for the SID pair
|
|
* (@ssid, @tsid) and class @tclass.
|
|
* The access vectors and the sequence number are
|
|
* normally provided by the security server in
|
|
* response to a security_compute_av() call. If the
|
|
* sequence number @avd->seqno is not less than the latest
|
|
* revocation notification, then the function copies
|
|
* the access vectors into a cache entry, returns
|
|
* avc_node inserted. Otherwise, this function returns NULL.
|
|
*/
|
|
static struct avc_node *avc_insert(struct selinux_avc *avc,
|
|
u32 ssid, u32 tsid, u16 tclass,
|
|
struct av_decision *avd,
|
|
struct avc_xperms_node *xp_node)
|
|
{
|
|
struct avc_node *pos, *node = NULL;
|
|
int hvalue;
|
|
unsigned long flag;
|
|
spinlock_t *lock;
|
|
struct hlist_head *head;
|
|
|
|
if (avc_latest_notif_update(avc, avd->seqno, 1))
|
|
return NULL;
|
|
|
|
node = avc_alloc_node(avc);
|
|
if (!node)
|
|
return NULL;
|
|
|
|
avc_node_populate(node, ssid, tsid, tclass, avd);
|
|
if (avc_xperms_populate(node, xp_node)) {
|
|
avc_node_kill(avc, node);
|
|
return NULL;
|
|
}
|
|
|
|
hvalue = avc_hash(ssid, tsid, tclass);
|
|
head = &avc->avc_cache.slots[hvalue];
|
|
lock = &avc->avc_cache.slots_lock[hvalue];
|
|
spin_lock_irqsave(lock, flag);
|
|
hlist_for_each_entry(pos, head, list) {
|
|
if (pos->ae.ssid == ssid &&
|
|
pos->ae.tsid == tsid &&
|
|
pos->ae.tclass == tclass) {
|
|
avc_node_replace(avc, node, pos);
|
|
goto found;
|
|
}
|
|
}
|
|
|
|
hlist_add_head_rcu(&node->list, head);
|
|
found:
|
|
spin_unlock_irqrestore(lock, flag);
|
|
return node;
|
|
}
|
|
|
|
/**
|
|
* avc_audit_pre_callback - SELinux specific information
|
|
* will be called by generic audit code
|
|
* @ab: the audit buffer
|
|
* @a: audit_data
|
|
*/
|
|
static void avc_audit_pre_callback(struct audit_buffer *ab, void *a)
|
|
{
|
|
struct common_audit_data *ad = a;
|
|
audit_log_format(ab, "avc: %s ",
|
|
ad->selinux_audit_data->denied ? "denied" : "granted");
|
|
avc_dump_av(ab, ad->selinux_audit_data->tclass,
|
|
ad->selinux_audit_data->audited);
|
|
audit_log_format(ab, " for ");
|
|
}
|
|
|
|
/**
|
|
* avc_audit_post_callback - SELinux specific information
|
|
* will be called by generic audit code
|
|
* @ab: the audit buffer
|
|
* @a: audit_data
|
|
*/
|
|
static void avc_audit_post_callback(struct audit_buffer *ab, void *a)
|
|
{
|
|
struct common_audit_data *ad = a;
|
|
audit_log_format(ab, " ");
|
|
avc_dump_query(ab, ad->selinux_audit_data->state,
|
|
ad->selinux_audit_data->ssid,
|
|
ad->selinux_audit_data->tsid,
|
|
ad->selinux_audit_data->tclass);
|
|
if (ad->selinux_audit_data->denied) {
|
|
audit_log_format(ab, " permissive=%u",
|
|
ad->selinux_audit_data->result ? 0 : 1);
|
|
}
|
|
}
|
|
|
|
/* This is the slow part of avc audit with big stack footprint */
|
|
noinline int slow_avc_audit(struct selinux_state *state,
|
|
u32 ssid, u32 tsid, u16 tclass,
|
|
u32 requested, u32 audited, u32 denied, int result,
|
|
struct common_audit_data *a)
|
|
{
|
|
struct common_audit_data stack_data;
|
|
struct selinux_audit_data sad;
|
|
|
|
if (!a) {
|
|
a = &stack_data;
|
|
a->type = LSM_AUDIT_DATA_NONE;
|
|
}
|
|
|
|
sad.tclass = tclass;
|
|
sad.requested = requested;
|
|
sad.ssid = ssid;
|
|
sad.tsid = tsid;
|
|
sad.audited = audited;
|
|
sad.denied = denied;
|
|
sad.result = result;
|
|
sad.state = state;
|
|
|
|
a->selinux_audit_data = &sad;
|
|
|
|
common_lsm_audit(a, avc_audit_pre_callback, avc_audit_post_callback);
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* avc_add_callback - Register a callback for security events.
|
|
* @callback: callback function
|
|
* @events: security events
|
|
*
|
|
* Register a callback function for events in the set @events.
|
|
* Returns %0 on success or -%ENOMEM if insufficient memory
|
|
* exists to add the callback.
|
|
*/
|
|
int __init avc_add_callback(int (*callback)(u32 event), u32 events)
|
|
{
|
|
struct avc_callback_node *c;
|
|
int rc = 0;
|
|
|
|
c = kmalloc(sizeof(*c), GFP_KERNEL);
|
|
if (!c) {
|
|
rc = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
c->callback = callback;
|
|
c->events = events;
|
|
c->next = avc_callbacks;
|
|
avc_callbacks = c;
|
|
out:
|
|
return rc;
|
|
}
|
|
|
|
/**
|
|
* avc_update_node Update an AVC entry
|
|
* @event : Updating event
|
|
* @perms : Permission mask bits
|
|
* @ssid,@tsid,@tclass : identifier of an AVC entry
|
|
* @seqno : sequence number when decision was made
|
|
* @xpd: extended_perms_decision to be added to the node
|
|
* @flags: the AVC_* flags, e.g. AVC_NONBLOCKING, AVC_EXTENDED_PERMS, or 0.
|
|
*
|
|
* if a valid AVC entry doesn't exist,this function returns -ENOENT.
|
|
* if kmalloc() called internal returns NULL, this function returns -ENOMEM.
|
|
* otherwise, this function updates the AVC entry. The original AVC-entry object
|
|
* will release later by RCU.
|
|
*/
|
|
static int avc_update_node(struct selinux_avc *avc,
|
|
u32 event, u32 perms, u8 driver, u8 xperm, u32 ssid,
|
|
u32 tsid, u16 tclass, u32 seqno,
|
|
struct extended_perms_decision *xpd,
|
|
u32 flags)
|
|
{
|
|
int hvalue, rc = 0;
|
|
unsigned long flag;
|
|
struct avc_node *pos, *node, *orig = NULL;
|
|
struct hlist_head *head;
|
|
spinlock_t *lock;
|
|
|
|
/*
|
|
* If we are in a non-blocking code path, e.g. VFS RCU walk,
|
|
* then we must not add permissions to a cache entry
|
|
* because we will not audit the denial. Otherwise,
|
|
* during the subsequent blocking retry (e.g. VFS ref walk), we
|
|
* will find the permissions already granted in the cache entry
|
|
* and won't audit anything at all, leading to silent denials in
|
|
* permissive mode that only appear when in enforcing mode.
|
|
*
|
|
* See the corresponding handling of MAY_NOT_BLOCK in avc_audit()
|
|
* and selinux_inode_permission().
|
|
*/
|
|
if (flags & AVC_NONBLOCKING)
|
|
return 0;
|
|
|
|
node = avc_alloc_node(avc);
|
|
if (!node) {
|
|
rc = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
/* Lock the target slot */
|
|
hvalue = avc_hash(ssid, tsid, tclass);
|
|
|
|
head = &avc->avc_cache.slots[hvalue];
|
|
lock = &avc->avc_cache.slots_lock[hvalue];
|
|
|
|
spin_lock_irqsave(lock, flag);
|
|
|
|
hlist_for_each_entry(pos, head, list) {
|
|
if (ssid == pos->ae.ssid &&
|
|
tsid == pos->ae.tsid &&
|
|
tclass == pos->ae.tclass &&
|
|
seqno == pos->ae.avd.seqno){
|
|
orig = pos;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!orig) {
|
|
rc = -ENOENT;
|
|
avc_node_kill(avc, node);
|
|
goto out_unlock;
|
|
}
|
|
|
|
/*
|
|
* Copy and replace original node.
|
|
*/
|
|
|
|
avc_node_populate(node, ssid, tsid, tclass, &orig->ae.avd);
|
|
|
|
if (orig->ae.xp_node) {
|
|
rc = avc_xperms_populate(node, orig->ae.xp_node);
|
|
if (rc) {
|
|
avc_node_kill(avc, node);
|
|
goto out_unlock;
|
|
}
|
|
}
|
|
|
|
switch (event) {
|
|
case AVC_CALLBACK_GRANT:
|
|
node->ae.avd.allowed |= perms;
|
|
if (node->ae.xp_node && (flags & AVC_EXTENDED_PERMS))
|
|
avc_xperms_allow_perm(node->ae.xp_node, driver, xperm);
|
|
break;
|
|
case AVC_CALLBACK_TRY_REVOKE:
|
|
case AVC_CALLBACK_REVOKE:
|
|
node->ae.avd.allowed &= ~perms;
|
|
break;
|
|
case AVC_CALLBACK_AUDITALLOW_ENABLE:
|
|
node->ae.avd.auditallow |= perms;
|
|
break;
|
|
case AVC_CALLBACK_AUDITALLOW_DISABLE:
|
|
node->ae.avd.auditallow &= ~perms;
|
|
break;
|
|
case AVC_CALLBACK_AUDITDENY_ENABLE:
|
|
node->ae.avd.auditdeny |= perms;
|
|
break;
|
|
case AVC_CALLBACK_AUDITDENY_DISABLE:
|
|
node->ae.avd.auditdeny &= ~perms;
|
|
break;
|
|
case AVC_CALLBACK_ADD_XPERMS:
|
|
avc_add_xperms_decision(node, xpd);
|
|
break;
|
|
}
|
|
avc_node_replace(avc, node, orig);
|
|
out_unlock:
|
|
spin_unlock_irqrestore(lock, flag);
|
|
out:
|
|
return rc;
|
|
}
|
|
|
|
/**
|
|
* avc_flush - Flush the cache
|
|
*/
|
|
static void avc_flush(struct selinux_avc *avc)
|
|
{
|
|
struct hlist_head *head;
|
|
struct avc_node *node;
|
|
spinlock_t *lock;
|
|
unsigned long flag;
|
|
int i;
|
|
|
|
for (i = 0; i < AVC_CACHE_SLOTS; i++) {
|
|
head = &avc->avc_cache.slots[i];
|
|
lock = &avc->avc_cache.slots_lock[i];
|
|
|
|
spin_lock_irqsave(lock, flag);
|
|
/*
|
|
* With preemptable RCU, the outer spinlock does not
|
|
* prevent RCU grace periods from ending.
|
|
*/
|
|
rcu_read_lock();
|
|
hlist_for_each_entry(node, head, list)
|
|
avc_node_delete(avc, node);
|
|
rcu_read_unlock();
|
|
spin_unlock_irqrestore(lock, flag);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* avc_ss_reset - Flush the cache and revalidate migrated permissions.
|
|
* @seqno: policy sequence number
|
|
*/
|
|
int avc_ss_reset(struct selinux_avc *avc, u32 seqno)
|
|
{
|
|
struct avc_callback_node *c;
|
|
int rc = 0, tmprc;
|
|
|
|
avc_flush(avc);
|
|
|
|
for (c = avc_callbacks; c; c = c->next) {
|
|
if (c->events & AVC_CALLBACK_RESET) {
|
|
tmprc = c->callback(AVC_CALLBACK_RESET);
|
|
/* save the first error encountered for the return
|
|
value and continue processing the callbacks */
|
|
if (!rc)
|
|
rc = tmprc;
|
|
}
|
|
}
|
|
|
|
avc_latest_notif_update(avc, seqno, 0);
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
* Slow-path helper function for avc_has_perm_noaudit,
|
|
* when the avc_node lookup fails. We get called with
|
|
* the RCU read lock held, and need to return with it
|
|
* still held, but drop if for the security compute.
|
|
*
|
|
* Don't inline this, since it's the slow-path and just
|
|
* results in a bigger stack frame.
|
|
*/
|
|
static noinline
|
|
struct avc_node *avc_compute_av(struct selinux_state *state,
|
|
u32 ssid, u32 tsid,
|
|
u16 tclass, struct av_decision *avd,
|
|
struct avc_xperms_node *xp_node)
|
|
{
|
|
rcu_read_unlock();
|
|
INIT_LIST_HEAD(&xp_node->xpd_head);
|
|
security_compute_av(state, ssid, tsid, tclass, avd, &xp_node->xp);
|
|
rcu_read_lock();
|
|
return avc_insert(state->avc, ssid, tsid, tclass, avd, xp_node);
|
|
}
|
|
|
|
static noinline int avc_denied(struct selinux_state *state,
|
|
u32 ssid, u32 tsid,
|
|
u16 tclass, u32 requested,
|
|
u8 driver, u8 xperm, unsigned int flags,
|
|
struct av_decision *avd)
|
|
{
|
|
if (flags & AVC_STRICT)
|
|
return -EACCES;
|
|
|
|
if (enforcing_enabled(state) &&
|
|
!(avd->flags & AVD_FLAGS_PERMISSIVE))
|
|
return -EACCES;
|
|
|
|
avc_update_node(state->avc, AVC_CALLBACK_GRANT, requested, driver,
|
|
xperm, ssid, tsid, tclass, avd->seqno, NULL, flags);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* The avc extended permissions logic adds an additional 256 bits of
|
|
* permissions to an avc node when extended permissions for that node are
|
|
* specified in the avtab. If the additional 256 permissions is not adequate,
|
|
* as-is the case with ioctls, then multiple may be chained together and the
|
|
* driver field is used to specify which set contains the permission.
|
|
*/
|
|
int avc_has_extended_perms(struct selinux_state *state,
|
|
u32 ssid, u32 tsid, u16 tclass, u32 requested,
|
|
u8 driver, u8 xperm, struct common_audit_data *ad)
|
|
{
|
|
struct avc_node *node;
|
|
struct av_decision avd;
|
|
u32 denied;
|
|
struct extended_perms_decision local_xpd;
|
|
struct extended_perms_decision *xpd = NULL;
|
|
struct extended_perms_data allowed;
|
|
struct extended_perms_data auditallow;
|
|
struct extended_perms_data dontaudit;
|
|
struct avc_xperms_node local_xp_node;
|
|
struct avc_xperms_node *xp_node;
|
|
int rc = 0, rc2;
|
|
|
|
xp_node = &local_xp_node;
|
|
BUG_ON(!requested);
|
|
|
|
rcu_read_lock();
|
|
|
|
node = avc_lookup(state->avc, ssid, tsid, tclass);
|
|
if (unlikely(!node)) {
|
|
node = avc_compute_av(state, ssid, tsid, tclass, &avd, xp_node);
|
|
} else {
|
|
memcpy(&avd, &node->ae.avd, sizeof(avd));
|
|
xp_node = node->ae.xp_node;
|
|
}
|
|
/* if extended permissions are not defined, only consider av_decision */
|
|
if (!xp_node || !xp_node->xp.len)
|
|
goto decision;
|
|
|
|
local_xpd.allowed = &allowed;
|
|
local_xpd.auditallow = &auditallow;
|
|
local_xpd.dontaudit = &dontaudit;
|
|
|
|
xpd = avc_xperms_decision_lookup(driver, xp_node);
|
|
if (unlikely(!xpd)) {
|
|
/*
|
|
* Compute the extended_perms_decision only if the driver
|
|
* is flagged
|
|
*/
|
|
if (!security_xperm_test(xp_node->xp.drivers.p, driver)) {
|
|
avd.allowed &= ~requested;
|
|
goto decision;
|
|
}
|
|
rcu_read_unlock();
|
|
security_compute_xperms_decision(state, ssid, tsid, tclass,
|
|
driver, &local_xpd);
|
|
rcu_read_lock();
|
|
avc_update_node(state->avc, AVC_CALLBACK_ADD_XPERMS, requested,
|
|
driver, xperm, ssid, tsid, tclass, avd.seqno,
|
|
&local_xpd, 0);
|
|
} else {
|
|
avc_quick_copy_xperms_decision(xperm, &local_xpd, xpd);
|
|
}
|
|
xpd = &local_xpd;
|
|
|
|
if (!avc_xperms_has_perm(xpd, xperm, XPERMS_ALLOWED))
|
|
avd.allowed &= ~requested;
|
|
|
|
decision:
|
|
denied = requested & ~(avd.allowed);
|
|
if (unlikely(denied))
|
|
rc = avc_denied(state, ssid, tsid, tclass, requested,
|
|
driver, xperm, AVC_EXTENDED_PERMS, &avd);
|
|
|
|
rcu_read_unlock();
|
|
|
|
rc2 = avc_xperms_audit(state, ssid, tsid, tclass, requested,
|
|
&avd, xpd, xperm, rc, ad);
|
|
if (rc2)
|
|
return rc2;
|
|
return rc;
|
|
}
|
|
|
|
/**
|
|
* avc_has_perm_noaudit - Check permissions but perform no auditing.
|
|
* @ssid: source security identifier
|
|
* @tsid: target security identifier
|
|
* @tclass: target security class
|
|
* @requested: requested permissions, interpreted based on @tclass
|
|
* @flags: AVC_STRICT, AVC_NONBLOCKING, or 0
|
|
* @avd: access vector decisions
|
|
*
|
|
* Check the AVC to determine whether the @requested permissions are granted
|
|
* for the SID pair (@ssid, @tsid), interpreting the permissions
|
|
* based on @tclass, and call the security server on a cache miss to obtain
|
|
* a new decision and add it to the cache. Return a copy of the decisions
|
|
* in @avd. Return %0 if all @requested permissions are granted,
|
|
* -%EACCES if any permissions are denied, or another -errno upon
|
|
* other errors. This function is typically called by avc_has_perm(),
|
|
* but may also be called directly to separate permission checking from
|
|
* auditing, e.g. in cases where a lock must be held for the check but
|
|
* should be released for the auditing.
|
|
*/
|
|
inline int avc_has_perm_noaudit(struct selinux_state *state,
|
|
u32 ssid, u32 tsid,
|
|
u16 tclass, u32 requested,
|
|
unsigned int flags,
|
|
struct av_decision *avd)
|
|
{
|
|
struct avc_node *node;
|
|
struct avc_xperms_node xp_node;
|
|
int rc = 0;
|
|
u32 denied;
|
|
|
|
BUG_ON(!requested);
|
|
|
|
rcu_read_lock();
|
|
|
|
node = avc_lookup(state->avc, ssid, tsid, tclass);
|
|
if (unlikely(!node))
|
|
node = avc_compute_av(state, ssid, tsid, tclass, avd, &xp_node);
|
|
else
|
|
memcpy(avd, &node->ae.avd, sizeof(*avd));
|
|
|
|
denied = requested & ~(avd->allowed);
|
|
if (unlikely(denied))
|
|
rc = avc_denied(state, ssid, tsid, tclass, requested, 0, 0,
|
|
flags, avd);
|
|
|
|
rcu_read_unlock();
|
|
return rc;
|
|
}
|
|
|
|
/**
|
|
* avc_has_perm - Check permissions and perform any appropriate auditing.
|
|
* @ssid: source security identifier
|
|
* @tsid: target security identifier
|
|
* @tclass: target security class
|
|
* @requested: requested permissions, interpreted based on @tclass
|
|
* @auditdata: auxiliary audit data
|
|
*
|
|
* Check the AVC to determine whether the @requested permissions are granted
|
|
* for the SID pair (@ssid, @tsid), interpreting the permissions
|
|
* based on @tclass, and call the security server on a cache miss to obtain
|
|
* a new decision and add it to the cache. Audit the granting or denial of
|
|
* permissions in accordance with the policy. Return %0 if all @requested
|
|
* permissions are granted, -%EACCES if any permissions are denied, or
|
|
* another -errno upon other errors.
|
|
*/
|
|
int avc_has_perm(struct selinux_state *state, u32 ssid, u32 tsid, u16 tclass,
|
|
u32 requested, struct common_audit_data *auditdata)
|
|
{
|
|
struct av_decision avd;
|
|
int rc, rc2;
|
|
|
|
rc = avc_has_perm_noaudit(state, ssid, tsid, tclass, requested, 0,
|
|
&avd);
|
|
|
|
rc2 = avc_audit(state, ssid, tsid, tclass, requested, &avd, rc,
|
|
auditdata, 0);
|
|
if (rc2)
|
|
return rc2;
|
|
return rc;
|
|
}
|
|
|
|
int avc_has_perm_flags(struct selinux_state *state,
|
|
u32 ssid, u32 tsid, u16 tclass, u32 requested,
|
|
struct common_audit_data *auditdata,
|
|
int flags)
|
|
{
|
|
struct av_decision avd;
|
|
int rc, rc2;
|
|
|
|
rc = avc_has_perm_noaudit(state, ssid, tsid, tclass, requested,
|
|
(flags & MAY_NOT_BLOCK) ? AVC_NONBLOCKING : 0,
|
|
&avd);
|
|
|
|
rc2 = avc_audit(state, ssid, tsid, tclass, requested, &avd, rc,
|
|
auditdata, flags);
|
|
if (rc2)
|
|
return rc2;
|
|
return rc;
|
|
}
|
|
|
|
u32 avc_policy_seqno(struct selinux_state *state)
|
|
{
|
|
return state->avc->avc_cache.latest_notif;
|
|
}
|
|
|
|
void avc_disable(void)
|
|
{
|
|
/*
|
|
* If you are looking at this because you have realized that we are
|
|
* not destroying the avc_node_cachep it might be easy to fix, but
|
|
* I don't know the memory barrier semantics well enough to know. It's
|
|
* possible that some other task dereferenced security_ops when
|
|
* it still pointed to selinux operations. If that is the case it's
|
|
* possible that it is about to use the avc and is about to need the
|
|
* avc_node_cachep. I know I could wrap the security.c security_ops call
|
|
* in an rcu_lock, but seriously, it's not worth it. Instead I just flush
|
|
* the cache and get that memory back.
|
|
*/
|
|
if (avc_node_cachep) {
|
|
avc_flush(selinux_state.avc);
|
|
/* kmem_cache_destroy(avc_node_cachep); */
|
|
}
|
|
}
|