https://source.android.com/docs/security/bulletin/2023-10-01 * tag 'ASB-2023-10-06_4.19-stable' of https://android.googlesource.com/kernel/common: UPSTREAM: net/sched: sch_hfsc: Ensure inner classes have fsc curve UPSTREAM: net: sched: sch_qfq: Fix UAF in qfq_dequeue() Linux 4.19.295 net/sched: Retire rsvp classifier net/sched: cls_fw: No longer copy tcf_result on update to avoid use-after-free mtd: rawnand: brcmnand: Fix ECC level field setting for v7.2 controller nfsd: fix change_info in NFSv4 RENAME replies btrfs: fix lockdep splat and potential deadlock after failure running delayed items attr: block mode changes of symlinks md/raid1: fix error: ISO C90 forbids mixed declarations kobject: Add sanity check for kset->kobj.ktype in kset_register() media: pci: ipu3-cio2: Initialise timing struct to avoid a compiler warning serial: cpm_uart: Avoid suspicious locking scsi: target: iscsi: Fix buffer overflow in lio_target_nacl_info_show() usb: gadget: fsl_qe_udc: validate endpoint index for ch9 udc media: pci: cx23885: replace BUG with error return media: tuners: qt1010: replace BUG_ON with a regular error iio: core: Use min() instead of min_t() to make code more robust media: az6007: Fix null-ptr-deref in az6007_i2c_xfer() media: anysee: fix null-ptr-deref in anysee_master_xfer media: af9005: Fix null-ptr-deref in af9005_i2c_xfer media: dw2102: Fix null-ptr-deref in dw2102_i2c_transfer() media: dvb-usb-v2: af9035: Fix null-ptr-deref in af9035_i2c_master_xfer powerpc/pseries: fix possible memory leak in ibmebus_bus_init() jfs: fix invalid free of JFS_IP(ipimap)->i_imap in diUnmount fs/jfs: prevent double-free in dbUnmount() after failed jfs_remount() ext2: fix datatype of block number in ext2_xattr_set2() md: raid1: fix potential OOB in raid1_remove_disk() drm/exynos: fix a possible null-pointer dereference due to data race in exynos_drm_crtc_atomic_disable() alx: fix OOB-read compiler warning tpm_tis: Resend command to recover from data transfer errors crypto: lib/mpi - avoid null pointer deref in mpi_cmp_ui() wifi: mwifiex: fix fortify warning wifi: ath9k: fix printk specifier hw_breakpoint: fix single-stepping when using bpf_overflow_handler ACPI: video: Add backlight=native DMI quirk for Lenovo Ideapad Z470 ACPICA: Add AML_NO_OPERAND_RESOLVE flag to Timer btrfs: output extra debug info if we failed to find an inline backref autofs: fix memory leak of waitqueues in autofs_catatonic_mode parisc: Drop loops_per_jiffy from per_cpu struct drm/amd/display: Fix a bug when searching for insert_above_mpcc kcm: Fix error handling for SOCK_DGRAM in kcm_sendmsg(). ixgbe: fix timestamp configuration code kcm: Fix memory leak in error path of kcm_sendmsg() net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all() perf hists browser: Fix hierarchy mode header mtd: rawnand: brcmnand: Fix potential false time out warning mtd: rawnand: brcmnand: Fix potential out-of-bounds access in oob write mtd: rawnand: brcmnand: Fix crash during the panic_write btrfs: don't start transaction when joining with TRANS_JOIN_NOSTART ata: pata_ftide010: Add missing MODULE_DESCRIPTION ata: sata_gemini: Add missing MODULE_DESCRIPTION netfilter: nfnetlink_osf: avoid OOB read idr: fix param name in idr_alloc_cyclic() doc igb: Change IGB_MIN to allow set rx/tx value between 64 and 80 igbvf: Change IGBVF_MIN to allow set rx/tx value between 64 and 80 kcm: Destroy mutex in kcm_exit_net() net: sched: sch_qfq: Fix UAF in qfq_dequeue() af_unix: Fix data race around sk->sk_err. af_unix: Fix data-races around sk->sk_shutdown. af_unix: Fix data-race around unix_tot_inflight. af_unix: Fix data-races around user->unix_inflight. net: ipv6/addrconf: avoid integer underflow in ipv6_create_tempaddr veth: Fixing transmit return status for dropped packets igb: disable virtualization features on 82580 net: read sk->sk_family once in sk_mc_loop() pwm: lpc32xx: Remove handling of PWM channels watchdog: intel-mid_wdt: add MODULE_ALIAS() to allow auto-load x86/virt: Drop unnecessary check on extended CPUID level in cpu_has_svm() kconfig: fix possible buffer overflow NFSv4/pnfs: minor fix for cleanup path in nfs4_get_device_info soc: qcom: qmi_encdec: Restrict string length in decode clk: qcom: gcc-mdm9615: use proper parent for pll0_vote clock parisc: led: Reduce CPU overhead for disk & lan LED computation parisc: led: Fix LAN receive and transmit LEDs drm/ast: Fix DRAM init on AST2200 fbdev/ep93xx-fb: Do not assign to struct fb_info.dev scsi: qla2xxx: Turn off noisy message log scsi: qla2xxx: fix inconsistent TMF timeout udf: initialize newblock to 0 usb: typec: tcpci: clear the fault status bit serial: sc16is7xx: fix broken port 0 uart init sc16is7xx: Set iobase to device index PCI/ATS: Add inline to pci_prg_resp_pasid_required() pstore/ram: Check start of empty przs during init net: handle ARPHRD_PPP in dev_is_mac_header_xmit() X.509: if signature is unsupported skip validation cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug crypto: stm32 - fix loop iterating through scatterlist for DMA dccp: Fix out of bounds access in DCCP error handler dlm: fix plock lookup when using multiple lockspaces parisc: Fix /proc/cpuinfo output for lscpu procfs: block chmod on /proc/thread-self/comm Revert "PCI: Mark NVIDIA T4 GPUs to avoid bus reset" ntb: Fix calculation ntb_transport_tx_free_entry() ntb: Clean up tx tail index on link down ntb: Drop packets when qp link is down media: dvb: symbol fixup for dvb_attach() backlight/lv5207lp: Compare against struct fb_info.device backlight/bd6107: Compare against struct fb_info.device backlight/gpio_backlight: Compare against struct fb_info.device ARM: OMAP2+: Fix -Warray-bounds warning in _pwrdm_state_switch() ipmi_si: fix a memleak in try_smi_init() ALSA: pcm: Fix missing fixup call in compat hw_refine ioctl PM / devfreq: Fix leak in devfreq_dev_release() igb: set max size RX buffer when store bad packet is enabled skbuff: skb_segment, Call zero copy functions before using skbuff frags netfilter: xt_sctp: validate the flag_info count netfilter: xt_u32: validate user space input netfilter: ipset: add the missing IP_SET_HASH_WITH_NET0 macro for ip_set_hash_netportnet.c igmp: limit igmpv3_newpack() packet size to IP_MAX_MTU dmaengine: ste_dma40: Add missing IRQ check in d40_probe um: Fix hostaudio build errors arch: um: drivers: Kconfig: pedantic formatting rpmsg: glink: Add check for kstrdup HID: multitouch: Correct devm device reference for hidinput input_dev name Revert "IB/isert: Fix incorrect release of isert connection" amba: bus: fix refcount leak serial: tegra: handle clk prepare error in tegra_uart_hw_init() scsi: fcoe: Fix potential deadlock on &fip->ctlr_lock scsi: core: Use 32-bit hostnum in scsi_host_lookup() cgroup:namespace: Remove unused cgroup_namespaces_init() media: ov2680: Fix regulators being left enabled on ov2680_power_on() errors media: ov2680: Fix vflip / hflip set functions media: ov2680: Fix ov2680_bayer_order() media: ov2680: Remove auto-gain and auto-exposure controls media: i2c: ov2680: Set V4L2_CTRL_FLAG_MODIFY_LAYOUT on flips USB: gadget: f_mass_storage: Fix unused variable warning media: go7007: Remove redundant if statement IB/uverbs: Fix an potential error pointer dereference dma-buf/sync_file: Fix docs syntax scsi: qedf: Do not touch __user pointer in qedf_dbg_fp_int_cmd_read() directly scsi: qedf: Do not touch __user pointer in qedf_dbg_stop_io_on_error_cmd_read() directly x86/APM: drop the duplicate APM_MINOR_DEV macro scsi: qla4xxx: Add length check when parsing nlattrs scsi: be2iscsi: Add length check when parsing nlattrs scsi: iscsi: Add strlen() check in iscsi_if_set{_host}_param() usb: phy: mxs: fix getting wrong state with mxs_phy_is_otg_host() media: mediatek: vcodec: Return NULL if no vdec_fb is found media: cx24120: Add retval check for cx24120_message_send() media: dvb-usb: m920x: Fix a potential memory leak in m920x_i2c_xfer() media: dib7000p: Fix potential division by zero drivers: usb: smsusb: fix error handling code in smsusb_init_device media: v4l2-core: Fix a potential resource leak in v4l2_fwnode_parse_link() media: v4l2-fwnode: simplify v4l2_fwnode_parse_link media: v4l2-fwnode: fix v4l2_fwnode_parse_link handling media: Use of_node_name_eq for node name comparisons NFSD: da_addr_body field missing in some GETDEVICEINFO replies fs: lockd: avoid possible wrong NULL parameter jfs: validate max amount of blocks before allocation. powerpc/iommu: Fix notifiers being shared by PCI and VIO buses nfs/blocklayout: Use the passed in gfp flags wifi: ath10k: Use RMW accessors for changing LNKCTL drm/radeon: Use RMW accessors for changing LNKCTL drm/radeon: Prefer pcie_capability_read_word() drm/radeon: Replace numbers with PCI_EXP_LNKCTL2 definitions drm/radeon: Correct Transmit Margin masks drm/amdgpu: Use RMW accessors for changing LNKCTL drm/amdgpu: Prefer pcie_capability_read_word() drm/amdgpu: Replace numbers with PCI_EXP_LNKCTL2 definitions drm/amdgpu: Correct Transmit Margin masks PCI: Add #defines for Enter Compliance, Transmit Margin PCI: Decode PCIe 32 GT/s link speed PCI: Cleanup register definition width and whitespace PCI/ATS: Add pci_prg_resp_pasid_required() interface. PCI/ASPM: Use RMW accessors for changing LNKCTL PCI: pciehp: Use RMW accessors for changing LNKCTL PCI: Mark NVIDIA T4 GPUs to avoid bus reset clk: sunxi-ng: Modify mismatched function name drivers: clk: keystone: Fix parameter judgment in _of_pll_clk_init() ALSA: ac97: Fix possible error value of *rac97 of: unittest: Fix overlay type in apply/revert check audit: fix possible soft lockup in __audit_inode_child() smackfs: Prevent underflow in smk_set_cipso() drm/msm/mdp5: Don't leak some plane state drm/msm: Replace drm_framebuffer_{un/reference} with put, get functions of: unittest: fix null pointer dereferencing in of_unittest_find_node_by_name() drm/tegra: dpaux: Fix incorrect return value of platform_get_irq drm/tegra: Remove superfluous error messages around platform_get_irq() ARM: dts: BCM53573: Fix Ethernet info for Luxul devices drm: adv7511: Fix low refresh rate register for ADV7533/5 ARM: dts: samsung: s5pv210-smdkv210: correct ethernet reg addresses (split) ARM: dts: s5pv210: add dummy 5V regulator for backlight on SMDKv210 ARM: dts: s5pv210: correct ethernet unit address in SMDKV210 ARM: dts: s5pv210: use defines for IRQ flags in SMDKV210 ARM: dts: s5pv210: add RTC 32 KHz clock in SMDKV210 ARM: dts: samsung: s3c6410-mini6410: correct ethernet reg addresses (split) ARM: dts: s3c64xx: align pinctrl with dtschema ARM: dts: s3c6410: align node SROM bus node name with dtschema in Mini6410 ARM: dts: s3c6410: move fixed clocks under root node in Mini6410 ARM: dts: BCM53573: Use updated "spi-gpio" binding properties ARM: dts: BCM53573: Add cells sizes to PCIe node ARM: dts: BCM53573: Drop nonexistent #usb-cells ARM: dts: BCM53573: Describe on-SoC BCM53125 rev 4 switch ARM: dts: BCM5301X: Harmonize EHCI/OHCI DT nodes name drm/amdgpu: avoid integer overflow warning in amdgpu_device_resize_fb_bar() arm64: dts: qcom: msm8996: Add missing interrupt to the USB2 controller arm64: dts: msm8996: thermal: Add interrupt support quota: fix dqput() to follow the guarantees dquot_srcu should provide quota: add new helper dquot_active() quota: rename dquot_active() to inode_quota_active() quota: factor out dquot_write_dquot() quota: avoid increasing DQST_LOOKUPS when iterating over dirty/inuse list quota: add dqi_dirty_list description to comment of Dquot List Management netrom: Deny concurrent connect(). net/sched: sch_hfsc: Ensure inner classes have fsc curve net: arcnet: Do not call kfree_skb() under local_irq_disable() wifi: ath9k: use IS_ERR() with debugfs_create_dir() wifi: mwifiex: avoid possible NULL skb pointer dereference wifi: ath9k: protect WMI command response buffer replacement with a lock wifi: ath9k: fix races between ath9k_wmi_cmd and ath9k_wmi_ctrl_rx wifi: mwifiex: Fix missed return in oob checks failed path wifi: mwifiex: fix memory leak in mwifiex_histogram_read() fs: ocfs2: namei: check return value of ocfs2_add_entry() lwt: Check LWTUNNEL_XMIT_CONTINUE strictly crypto: caam - fix unchecked return value error Bluetooth: nokia: fix value check in nokia_bluetooth_serdev_probe() wifi: mwifiex: fix error recovery in PCIE buffer descriptor management mwifiex: switch from 'pci_' to 'dma_' API mwifiex: drop 'set_consistent_dma_mask' log message wifi: mwifiex: Fix OOB and integer underflow when rx packets can: gs_usb: gs_usb_receive_bulk_callback(): count RX overflow errors also in case of OOM spi: tegra20-sflash: fix to check return value of platform_get_irq() in tegra_sflash_probe() regmap: rbtree: Use alloc_flags for memory allocations tcp: tcp_enter_quickack_mode() should be static bpf: Clear the probe_addr for uprobe cpufreq: powernow-k8: Use related_cpus instead of cpus in driver.exit() fs: Fix error checking for d_hash_and_lookup() netfilter: nf_tables: missing NFT_TRANS_PREPARE_ERROR in flowtable deactivatation netfilter: nft_flow_offload: fix underflow in flowtable reference counter new helper: lookup_positive_unlocked() eventfd: prevent underflow for eventfd semaphores eventfd: Export eventfd_ctx_do_read() reiserfs: Check the return value from __getblk() Revert "net: macsec: preserve ingress frame ordering" udf: Handle error when adding extent to a file udf: Check consistency of Space Bitmap Descriptor powerpc/32s: Fix assembler warning about r0 powerpc/32: Include .branch_lt in data section net: Avoid address overwrite in kernel_connect ALSA: seq: oss: Fix racy open/close of MIDI devices cifs: add a warning when the in-flight count goes negative sctp: handle invalid error codes without calling BUG() bnx2x: fix page fault following EEH recovery netlabel: fix shift wrapping bug in netlbl_catmap_setlong() scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock idmaengine: make FSL_EDMA and INTEL_IDMA64 depends on HAS_IOMEM net: usb: qmi_wwan: add Quectel EM05GV2 security: keys: perform capable check only on privileged operations platform/x86: intel: hid: Always call BTNL ACPI method ASoC: atmel: Fix the 8K sample parameter in I2SC master ASoc: codecs: ES8316: Fix DMIC config fs/nls: make load_nls() take a const parameter s390/dasd: fix hanging device after request requeue s390/dasd: use correct number of retries for ERP requests m68k: Fix invalid .section syntax vxlan: generalize vxlan_parse_gpe_hdr and remove unused args ethernet: atheros: fix return value check in atl1c_tso_csum() ASoC: da7219: Check for failure reading AAD IRQ events ASoC: da7219: Flush pending AAD IRQ when suspending 9p: virtio: make sure 'offs' is initialized in zc_request pinctrl: amd: Don't show `Invalid config param` errors nilfs2: fix WARNING in mark_buffer_dirty due to discarded buffer reuse nilfs2: fix general protection fault in nilfs_lookup_dirty_data_buffers() fsi: master-ast-cf: Add MODULE_FIRMWARE macro serial: sc16is7xx: fix bug when first setting GPIO direction Bluetooth: btsdio: fix use after free bug in btsdio_remove due to race condition HID: wacom: remove the battery when the EKR is off USB: serial: option: add FOXCONN T99W368/T99W373 product USB: serial: option: add Quectel EM05G variant (0x030e) modules: only allow symbol_get of EXPORT_SYMBOL_GPL modules rtc: ds1685: use EXPORT_SYMBOL_GPL for ds1685_rtc_poweroff mmc: au1xmmc: force non-modular build and remove symbol_get usage ARM: pxa: remove use of symbol_get() erofs: ensure that the post-EOF tails are all zeroed Conflicts: include/net/tcp.h Change-Id: Ia73d7be3d6cae8d4fd38da7c6d85a977840872d3
373 lines
11 KiB
C
373 lines
11 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* linux/fs/attr.c
|
|
*
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
* changes by Thomas Schoebel-Theuer
|
|
*/
|
|
|
|
#include <linux/export.h>
|
|
#include <linux/time.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/string.h>
|
|
#include <linux/sched/signal.h>
|
|
#include <linux/capability.h>
|
|
#include <linux/fsnotify.h>
|
|
#include <linux/fcntl.h>
|
|
#include <linux/security.h>
|
|
#include <linux/evm.h>
|
|
#include <linux/ima.h>
|
|
|
|
static bool chown_ok(const struct inode *inode, kuid_t uid)
|
|
{
|
|
if (uid_eq(current_fsuid(), inode->i_uid) &&
|
|
uid_eq(uid, inode->i_uid))
|
|
return true;
|
|
if (capable_wrt_inode_uidgid(inode, CAP_CHOWN))
|
|
return true;
|
|
if (uid_eq(inode->i_uid, INVALID_UID) &&
|
|
ns_capable(inode->i_sb->s_user_ns, CAP_CHOWN))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
static bool chgrp_ok(const struct inode *inode, kgid_t gid)
|
|
{
|
|
if (uid_eq(current_fsuid(), inode->i_uid) &&
|
|
(in_group_p(gid) || gid_eq(gid, inode->i_gid)))
|
|
return true;
|
|
if (capable_wrt_inode_uidgid(inode, CAP_CHOWN))
|
|
return true;
|
|
if (gid_eq(inode->i_gid, INVALID_GID) &&
|
|
ns_capable(inode->i_sb->s_user_ns, CAP_CHOWN))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* setattr_prepare - check if attribute changes to a dentry are allowed
|
|
* @dentry: dentry to check
|
|
* @attr: attributes to change
|
|
*
|
|
* Check if we are allowed to change the attributes contained in @attr
|
|
* in the given dentry. This includes the normal unix access permission
|
|
* checks, as well as checks for rlimits and others. The function also clears
|
|
* SGID bit from mode if user is not allowed to set it. Also file capabilities
|
|
* and IMA extended attributes are cleared if ATTR_KILL_PRIV is set.
|
|
*
|
|
* Should be called as the first thing in ->setattr implementations,
|
|
* possibly after taking additional locks.
|
|
*/
|
|
int setattr_prepare(struct dentry *dentry, struct iattr *attr)
|
|
{
|
|
struct inode *inode = d_inode(dentry);
|
|
unsigned int ia_valid = attr->ia_valid;
|
|
|
|
/*
|
|
* First check size constraints. These can't be overriden using
|
|
* ATTR_FORCE.
|
|
*/
|
|
if (ia_valid & ATTR_SIZE) {
|
|
int error = inode_newsize_ok(inode, attr->ia_size);
|
|
if (error)
|
|
return error;
|
|
}
|
|
|
|
/* If force is set do it anyway. */
|
|
if (ia_valid & ATTR_FORCE)
|
|
goto kill_priv;
|
|
|
|
/* Make sure a caller can chown. */
|
|
if ((ia_valid & ATTR_UID) && !chown_ok(inode, attr->ia_uid))
|
|
return -EPERM;
|
|
|
|
/* Make sure caller can chgrp. */
|
|
if ((ia_valid & ATTR_GID) && !chgrp_ok(inode, attr->ia_gid))
|
|
return -EPERM;
|
|
|
|
/* Make sure a caller can chmod. */
|
|
if (ia_valid & ATTR_MODE) {
|
|
if (!inode_owner_or_capable(inode))
|
|
return -EPERM;
|
|
/* Also check the setgid bit! */
|
|
if (!in_group_p((ia_valid & ATTR_GID) ? attr->ia_gid :
|
|
inode->i_gid) &&
|
|
!capable_wrt_inode_uidgid(inode, CAP_FSETID))
|
|
attr->ia_mode &= ~S_ISGID;
|
|
}
|
|
|
|
/* Check for setting the inode time. */
|
|
if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)) {
|
|
if (!inode_owner_or_capable(inode))
|
|
return -EPERM;
|
|
}
|
|
|
|
kill_priv:
|
|
/* User has permission for the change */
|
|
if (ia_valid & ATTR_KILL_PRIV) {
|
|
int error;
|
|
|
|
error = security_inode_killpriv(dentry);
|
|
if (error)
|
|
return error;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(setattr_prepare);
|
|
|
|
/**
|
|
* inode_newsize_ok - may this inode be truncated to a given size
|
|
* @inode: the inode to be truncated
|
|
* @offset: the new size to assign to the inode
|
|
*
|
|
* inode_newsize_ok must be called with i_mutex held.
|
|
*
|
|
* inode_newsize_ok will check filesystem limits and ulimits to check that the
|
|
* new inode size is within limits. inode_newsize_ok will also send SIGXFSZ
|
|
* when necessary. Caller must not proceed with inode size change if failure is
|
|
* returned. @inode must be a file (not directory), with appropriate
|
|
* permissions to allow truncate (inode_newsize_ok does NOT check these
|
|
* conditions).
|
|
*
|
|
* Return: 0 on success, -ve errno on failure
|
|
*/
|
|
int inode_newsize_ok(const struct inode *inode, loff_t offset)
|
|
{
|
|
if (offset < 0)
|
|
return -EINVAL;
|
|
if (inode->i_size < offset) {
|
|
unsigned long limit;
|
|
|
|
limit = rlimit(RLIMIT_FSIZE);
|
|
if (limit != RLIM_INFINITY && offset > limit)
|
|
goto out_sig;
|
|
if (offset > inode->i_sb->s_maxbytes)
|
|
goto out_big;
|
|
} else {
|
|
/*
|
|
* truncation of in-use swapfiles is disallowed - it would
|
|
* cause subsequent swapout to scribble on the now-freed
|
|
* blocks.
|
|
*/
|
|
if (IS_SWAPFILE(inode))
|
|
return -ETXTBSY;
|
|
}
|
|
|
|
return 0;
|
|
out_sig:
|
|
send_sig(SIGXFSZ, current, 0);
|
|
out_big:
|
|
return -EFBIG;
|
|
}
|
|
EXPORT_SYMBOL(inode_newsize_ok);
|
|
|
|
/**
|
|
* setattr_copy - copy simple metadata updates into the generic inode
|
|
* @inode: the inode to be updated
|
|
* @attr: the new attributes
|
|
*
|
|
* setattr_copy must be called with i_mutex held.
|
|
*
|
|
* setattr_copy updates the inode's metadata with that specified
|
|
* in attr. Noticeably missing is inode size update, which is more complex
|
|
* as it requires pagecache updates.
|
|
*
|
|
* The inode is not marked as dirty after this operation. The rationale is
|
|
* that for "simple" filesystems, the struct inode is the inode storage.
|
|
* The caller is free to mark the inode dirty afterwards if needed.
|
|
*/
|
|
void setattr_copy(struct inode *inode, const struct iattr *attr)
|
|
{
|
|
unsigned int ia_valid = attr->ia_valid;
|
|
|
|
if (ia_valid & ATTR_UID)
|
|
inode->i_uid = attr->ia_uid;
|
|
if (ia_valid & ATTR_GID)
|
|
inode->i_gid = attr->ia_gid;
|
|
if (ia_valid & ATTR_ATIME)
|
|
inode->i_atime = timespec64_trunc(attr->ia_atime,
|
|
inode->i_sb->s_time_gran);
|
|
if (ia_valid & ATTR_MTIME)
|
|
inode->i_mtime = timespec64_trunc(attr->ia_mtime,
|
|
inode->i_sb->s_time_gran);
|
|
if (ia_valid & ATTR_CTIME)
|
|
inode->i_ctime = timespec64_trunc(attr->ia_ctime,
|
|
inode->i_sb->s_time_gran);
|
|
if (ia_valid & ATTR_MODE) {
|
|
umode_t mode = attr->ia_mode;
|
|
|
|
if (!in_group_p(inode->i_gid) &&
|
|
!capable_wrt_inode_uidgid(inode, CAP_FSETID))
|
|
mode &= ~S_ISGID;
|
|
inode->i_mode = mode;
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(setattr_copy);
|
|
|
|
/**
|
|
* notify_change - modify attributes of a filesytem object
|
|
* @dentry: object affected
|
|
* @attr: new attributes
|
|
* @delegated_inode: returns inode, if the inode is delegated
|
|
*
|
|
* The caller must hold the i_mutex on the affected object.
|
|
*
|
|
* If notify_change discovers a delegation in need of breaking,
|
|
* it will return -EWOULDBLOCK and return a reference to the inode in
|
|
* delegated_inode. The caller should then break the delegation and
|
|
* retry. Because breaking a delegation may take a long time, the
|
|
* caller should drop the i_mutex before doing so.
|
|
*
|
|
* Alternatively, a caller may pass NULL for delegated_inode. This may
|
|
* be appropriate for callers that expect the underlying filesystem not
|
|
* to be NFS exported. Also, passing NULL is fine for callers holding
|
|
* the file open for write, as there can be no conflicting delegation in
|
|
* that case.
|
|
*/
|
|
int notify_change2(struct vfsmount *mnt, struct dentry * dentry, struct iattr * attr, struct inode **delegated_inode)
|
|
{
|
|
struct inode *inode = dentry->d_inode;
|
|
umode_t mode = inode->i_mode;
|
|
int error;
|
|
struct timespec64 now;
|
|
unsigned int ia_valid = attr->ia_valid;
|
|
|
|
WARN_ON_ONCE(!inode_is_locked(inode));
|
|
|
|
if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
|
|
if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
|
|
return -EPERM;
|
|
}
|
|
|
|
/*
|
|
* If utimes(2) and friends are called with times == NULL (or both
|
|
* times are UTIME_NOW), then we need to check for write permission
|
|
*/
|
|
if (ia_valid & ATTR_TOUCH) {
|
|
if (IS_IMMUTABLE(inode))
|
|
return -EPERM;
|
|
|
|
if (!inode_owner_or_capable(inode)) {
|
|
error = inode_permission2(mnt, inode, MAY_WRITE);
|
|
if (error)
|
|
return error;
|
|
}
|
|
}
|
|
|
|
if ((ia_valid & ATTR_MODE)) {
|
|
/*
|
|
* Don't allow changing the mode of symlinks:
|
|
*
|
|
* (1) The vfs doesn't take the mode of symlinks into account
|
|
* during permission checking.
|
|
* (2) This has never worked correctly. Most major filesystems
|
|
* did return EOPNOTSUPP due to interactions with POSIX ACLs
|
|
* but did still updated the mode of the symlink.
|
|
* This inconsistency led system call wrapper providers such
|
|
* as libc to block changing the mode of symlinks with
|
|
* EOPNOTSUPP already.
|
|
* (3) To even do this in the first place one would have to use
|
|
* specific file descriptors and quite some effort.
|
|
*/
|
|
if (S_ISLNK(inode->i_mode))
|
|
return -EOPNOTSUPP;
|
|
|
|
/* Flag setting protected by i_mutex */
|
|
if (is_sxid(attr->ia_mode))
|
|
inode->i_flags &= ~S_NOSEC;
|
|
}
|
|
|
|
now = current_time(inode);
|
|
|
|
attr->ia_ctime = now;
|
|
if (!(ia_valid & ATTR_ATIME_SET))
|
|
attr->ia_atime = now;
|
|
if (!(ia_valid & ATTR_MTIME_SET))
|
|
attr->ia_mtime = now;
|
|
if (ia_valid & ATTR_KILL_PRIV) {
|
|
error = security_inode_need_killpriv(dentry);
|
|
if (error < 0)
|
|
return error;
|
|
if (error == 0)
|
|
ia_valid = attr->ia_valid &= ~ATTR_KILL_PRIV;
|
|
}
|
|
|
|
/*
|
|
* We now pass ATTR_KILL_S*ID to the lower level setattr function so
|
|
* that the function has the ability to reinterpret a mode change
|
|
* that's due to these bits. This adds an implicit restriction that
|
|
* no function will ever call notify_change with both ATTR_MODE and
|
|
* ATTR_KILL_S*ID set.
|
|
*/
|
|
if ((ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID)) &&
|
|
(ia_valid & ATTR_MODE))
|
|
BUG();
|
|
|
|
if (ia_valid & ATTR_KILL_SUID) {
|
|
if (mode & S_ISUID) {
|
|
ia_valid = attr->ia_valid |= ATTR_MODE;
|
|
attr->ia_mode = (inode->i_mode & ~S_ISUID);
|
|
}
|
|
}
|
|
if (ia_valid & ATTR_KILL_SGID) {
|
|
if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
|
|
if (!(ia_valid & ATTR_MODE)) {
|
|
ia_valid = attr->ia_valid |= ATTR_MODE;
|
|
attr->ia_mode = inode->i_mode;
|
|
}
|
|
attr->ia_mode &= ~S_ISGID;
|
|
}
|
|
}
|
|
if (!(attr->ia_valid & ~(ATTR_KILL_SUID | ATTR_KILL_SGID)))
|
|
return 0;
|
|
|
|
/*
|
|
* Verify that uid/gid changes are valid in the target
|
|
* namespace of the superblock.
|
|
*/
|
|
if (ia_valid & ATTR_UID &&
|
|
!kuid_has_mapping(inode->i_sb->s_user_ns, attr->ia_uid))
|
|
return -EOVERFLOW;
|
|
if (ia_valid & ATTR_GID &&
|
|
!kgid_has_mapping(inode->i_sb->s_user_ns, attr->ia_gid))
|
|
return -EOVERFLOW;
|
|
|
|
/* Don't allow modifications of files with invalid uids or
|
|
* gids unless those uids & gids are being made valid.
|
|
*/
|
|
if (!(ia_valid & ATTR_UID) && !uid_valid(inode->i_uid))
|
|
return -EOVERFLOW;
|
|
if (!(ia_valid & ATTR_GID) && !gid_valid(inode->i_gid))
|
|
return -EOVERFLOW;
|
|
|
|
error = security_inode_setattr(dentry, attr);
|
|
if (error)
|
|
return error;
|
|
error = try_break_deleg(inode, delegated_inode);
|
|
if (error)
|
|
return error;
|
|
|
|
if (mnt && inode->i_op->setattr2)
|
|
error = inode->i_op->setattr2(mnt, dentry, attr);
|
|
else if (inode->i_op->setattr)
|
|
error = inode->i_op->setattr(dentry, attr);
|
|
else
|
|
error = simple_setattr(dentry, attr);
|
|
|
|
if (!error) {
|
|
fsnotify_change(dentry, ia_valid);
|
|
ima_inode_post_setattr(dentry);
|
|
evm_inode_post_setattr(dentry, ia_valid);
|
|
}
|
|
|
|
return error;
|
|
}
|
|
EXPORT_SYMBOL_GPL(notify_change2);
|
|
|
|
int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **delegated_inode)
|
|
{
|
|
return notify_change2(NULL, dentry, attr, delegated_inode);
|
|
}
|
|
EXPORT_SYMBOL(notify_change);
|