936f394ef7
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmPaFzoACgkQONu9yGCS aT6Y7Q//bOQ+QfUsJ9oi0hCQpC4L4REaM/WpqyWFn+/75KB4KDZ7IGaHAZ8UZSPQ DwZ0aoIAapQyAL7Q5WUDnG51Q07Xi4NfWPHNlz1FqAKdJu2D8uAmYP9I6M0JpEbg nV5ki8UXETkIu7EnfS7+5MjHLt99DaA+W0Z1J+qqXONRoszELUNfMdTZMoqVX5Vx gqmSpHmySt2mhSr8k4Inx5OvhF6pZ9mQVq0baUEieAcyaRXSRBBLTtOgntcYyq+R aAoCV5E+lLDZVkjntc6wKtTECD6zegfXCBqZdxQ1RUt5SBTn7K2XnGqQt+V3UbeH 5kFwUngvnpGDQeS8VuzWo+yGBLu0cp6PShP329SbO5o0bY8qRxiWfr37sxfMq/yh F947AjG2wWouCK4xle68/O6GvZNLtKJI1Z0MihpFKmeLbvL0S88rkSnhwjPQ5qBe kK8RfUATLKkl6XoTyJT/v/o+/tlAuHj3txrH3zsB0MQWuuxBkZ1JAAnmDnBCcvIJ BAr6HFRFr6kTfcREnMKkWr2EXO98DGrk0Eg9FTedm1F4RSL8iGQenTXNmRMhSxFv /MtF0sRwkstI+v7EINmmK+wNJeye03WjmWDjJVxIqOwfmGC5EfCGhGV4CfmdnBsE N18DZMZ5oc9ft/zmH9Pi/vJUlwRHDS52uQ3r7K3TYXHHveT62FE= =8rzU -----END PGP SIGNATURE----- Merge 6.1.9 into android14-6.1 Changes in 6.1.9 memory: tegra: Remove clients SID override programming memory: atmel-sdramc: Fix missing clk_disable_unprepare in atmel_ramc_probe() memory: mvebu-devbus: Fix missing clk_disable_unprepare in mvebu_devbus_probe() arm64: dts: qcom: sc8280xp: fix primary USB-DP PHY reset dmaengine: qcom: gpi: Set link_rx bit on GO TRE for rx operation dmaengine: ti: k3-udma: Do conditional decrement of UDMA_CHAN_RT_PEER_BCNT_REG soc: imx: imx8mp-blk-ctrl: enable global pixclk with HDMI_TX_PHY PD arm64: dts: imx8mp-phycore-som: Remove invalid PMIC property ARM: dts: imx6ul-pico-dwarf: Use 'clock-frequency' ARM: dts: imx7d-pico: Use 'clock-frequency' ARM: dts: imx6qdl-gw560x: Remove incorrect 'uart-has-rtscts' arm64: dts: verdin-imx8mm: fix dahlia audio playback arm64: dts: imx8mm-beacon: Fix ecspi2 pinmux arm64: dts: verdin-imx8mm: fix dev board audio playback arm64: dts: imx93-11x11-evk: correct clock and strobe pad setting ARM: imx: add missing of_node_put() soc: imx: imx8mp-blk-ctrl: don't set power device name arm64: dts: imx8mp: Fix missing GPC Interrupt arm64: dts: imx8mp: Fix power-domain typo arm64: dts: imx8mp-evk: pcie0-refclk cosmetic cleanup HID: intel_ish-hid: Add check for ishtp_dma_tx_map arm64: dts: imx8mm-venice-gw7901: fix USB2 controller OC polarity soc: imx8m: Fix incorrect check for of_clk_get_by_name() reset: ti-sci: honor TI_SCI_PROTOCOL setting when not COMPILE_TEST reset: uniphier-glue: Fix possible null-ptr-deref EDAC/highbank: Fix memory leak in highbank_mc_probe() firmware: arm_scmi: Harden shared memory access in fetch_response firmware: arm_scmi: Harden shared memory access in fetch_notification firmware: arm_scmi: Fix virtio channels cleanup on shutdown interconnect: qcom: msm8996: Provide UFS clocks to A2NoC interconnect: qcom: msm8996: Fix regmap max_register values HID: amd_sfh: Fix warning unwind goto tomoyo: fix broken dependency on *.conf.default RDMA/rxe: Fix inaccurate constants in rxe_type_info RDMA/rxe: Prevent faulty rkey generation erofs: fix kvcalloc() misuse with __GFP_NOFAIL arm64: dts: marvell: AC5/AC5X: Fix address for UART1 RDMA/core: Fix ib block iterator counter overflow IB/hfi1: Reject a zero-length user expected buffer IB/hfi1: Reserve user expected TIDs IB/hfi1: Fix expected receive setup error exit issues IB/hfi1: Immediately remove invalid memory from hardware IB/hfi1: Remove user expected buffer invalidate race affs: initialize fsdata in affs_truncate() PM: AVS: qcom-cpr: Fix an error handling path in cpr_probe() arm64: dts: qcom: msm8992: Don't use sfpb mutex arm64: dts: qcom: msm8992-libra: Fix the memory map kbuild: export top-level LDFLAGS_vmlinux only to scripts/Makefile.vmlinux kbuild: fix 'make modules' error when CONFIG_DEBUG_INFO_BTF_MODULES=y phy: ti: fix Kconfig warning and operator precedence drm/msm/gpu: Fix potential double-free NFSD: fix use-after-free in nfsd4_ssc_setup_dul() ARM: dts: at91: sam9x60: fix the ddr clock for sam9x60 drm/vc4: bo: Fix drmm_mutex_init memory hog phy: usb: sunplus: Fix potential null-ptr-deref in sp_usb_phy_probe() bpf: hash map, avoid deadlock with suitable hash mask amd-xgbe: TX Flow Ctrl Registers are h/w ver dependent amd-xgbe: Delay AN timeout during KR training bpf: Fix pointer-leak due to insufficient speculative store bypass mitigation drm/vc4: bo: Fix unused variable warning phy: rockchip-inno-usb2: Fix missing clk_disable_unprepare() in rockchip_usb2phy_power_on() net: nfc: Fix use-after-free in local_cleanup() net: wan: Add checks for NULL for utdm in undo_uhdlc_init and unmap_si_regs net: enetc: avoid deadlock in enetc_tx_onestep_tstamp() net: lan966x: add missing fwnode_handle_put() for ports node sch_htb: Avoid grafting on htb_destroy_class_offload when destroying htb gpio: mxc: Protect GPIO irqchip RMW with bgpio spinlock gpio: mxc: Always set GPIOs used as interrupt source to INPUT mode wifi: rndis_wlan: Prevent buffer overflow in rndis_query_oid pinctrl: rockchip: fix reading pull type on rk3568 net: stmmac: Fix queue statistics reading net/sched: sch_taprio: fix possible use-after-free l2tp: convert l2tp_tunnel_list to idr l2tp: close all race conditions in l2tp_tunnel_register() net: usb: sr9700: Handle negative len net: mdio: validate parameter addr in mdiobus_get_phy() HID: check empty report_list in hid_validate_values() HID: check empty report_list in bigben_probe() net: stmmac: fix invalid call to mdiobus_get_phy() pinctrl: rockchip: fix mux route data for rk3568 ARM: dts: stm32: Fix qspi pinctrl phandle for stm32mp15xx-dhcor-som ARM: dts: stm32: Fix qspi pinctrl phandle for stm32mp15xx-dhcom-som ARM: dts: stm32: Fix qspi pinctrl phandle for stm32mp157c-emstamp-argon ARM: dts: stm32: Fix qspi pinctrl phandle for stm32mp151a-prtt1l HID: revert CHERRY_MOUSE_000C quirk block/rnbd-clt: fix wrong max ID in ida_alloc_max usb: ucsi: Ensure connector delayed work items are flushed usb: gadget: f_fs: Prevent race during ffs_ep0_queue_wait usb: gadget: f_fs: Ensure ep0req is dequeued before free_request netfilter: conntrack: handle tcp challenge acks during connection reuse Bluetooth: Fix a buffer overflow in mgmt_mesh_add() Bluetooth: hci_conn: Fix memory leaks Bluetooth: hci_sync: fix memory leak in hci_update_adv_data() Bluetooth: ISO: Avoid circular locking dependency Bluetooth: ISO: Fix possible circular locking dependency Bluetooth: hci_event: Fix Invalid wait context Bluetooth: Fix possible deadlock in rfcomm_sk_state_change net: ipa: disable ipa interrupt during suspend net/mlx5e: Avoid false lock dependency warning on tc_ht even more net/mlx5: E-switch, Fix setting of reserved fields on MODIFY_SCHEDULING_ELEMENT net/mlx5e: QoS, Fix wrongfully setting parent_element_id on MODIFY_SCHEDULING_ELEMENT net/mlx5e: Set decap action based on attr for sample net/mlx5: E-switch, Fix switchdev mode after devlink reload net: mlx5: eliminate anonymous module_init & module_exit drm/panfrost: fix GENERIC_ATOMIC64 dependency dmaengine: Fix double increment of client_count in dma_chan_get() net: macb: fix PTP TX timestamp failure due to packet padding virtio-net: correctly enable callback during start_xmit l2tp: prevent lockdep issue in l2tp_tunnel_register() HID: betop: check shape of output reports drm/i915/selftests: Unwind hugepages to drop wakeref on error cifs: fix potential deadlock in cache_refresh_path() dmaengine: xilinx_dma: call of_node_put() when breaking out of for_each_child_of_node() dmaengine: tegra: Fix memory leak in terminate_all() phy: phy-can-transceiver: Skip warning if no "max-bitrate" drm/amd/display: fix issues with driver unload net: sched: gred: prevent races when adding offloads to stats nvme-pci: fix timeout request state check tcp: avoid the lookup process failing to get sk in ehash table usb: dwc3: fix extcon dependency ptdma: pt_core_execute_cmd() should use spinlock device property: fix of node refcount leak in fwnode_graph_get_next_endpoint() w1: fix deadloop in __w1_remove_master_device() w1: fix WARNING after calling w1_process() driver core: Fix test_async_probe_init saves device in wrong array selftests/net: toeplitz: fix race on tpacket_v3 block close net: dsa: microchip: ksz9477: port map correction in ALU table entry register thermal: Validate new state in cur_state_store() thermal/core: fix error code in __thermal_cooling_device_register() thermal: core: call put_device() only after device_register() fails net: stmmac: enable all safety features by default bnxt: Do not read past the end of test names tcp: fix rate_app_limited to default to 1 scsi: iscsi: Fix multiple iSCSI session unbind events sent to userspace ASoC: SOF: pm: Set target state earlier ASoC: SOF: pm: Always tear down pipelines before DSP suspend ASoC: SOF: Add FW state to debugfs ASoC: amd: yc: Add Razer Blade 14 2022 into DMI table spi: cadence: Fix busy cycles calculation cpufreq: CPPC: Add u64 casts to avoid overflowing cpufreq: Add Tegra234 to cpufreq-dt-platdev blocklist ASoC: mediatek: mt8186: support rt5682s_max98360 ASoC: mediatek: mt8186: Add machine support for max98357a ASoC: amd: yc: Add ASUS M5402RA into DMI table ASoC: support machine driver with max98360 kcsan: test: don't put the expect array on the stack cpufreq: Add SM6375 to cpufreq-dt-platdev blocklist ASoC: fsl_micfil: Correct the number of steps on SX controls drm/msm/a6xx: Avoid gx gbit halt during rpm suspend net: usb: cdc_ether: add support for Thales Cinterion PLS62-W modem drm: Add orientation quirk for Lenovo ideapad D330-10IGL s390/debug: add _ASM_S390_ prefix to header guard s390: expicitly align _edata and _end symbols on page boundary xen/pvcalls: free active map buffer on pvcalls_front_free_map perf/x86/cstate: Add Meteor Lake support perf/x86/msr: Add Meteor Lake support perf/x86/msr: Add Emerald Rapids perf/x86/intel/uncore: Add Emerald Rapids nolibc: fix fd_set type tools/nolibc: Fix S_ISxxx macros tools/nolibc: fix missing includes causing build issues at -O0 tools/nolibc: prevent gcc from making memset() loop over itself cpufreq: armada-37xx: stop using 0 as NULL pointer ASoC: fsl_ssi: Rename AC'97 streams to avoid collisions with AC'97 CODEC ASoC: fsl-asoc-card: Fix naming of AC'97 CODEC widgets ACPI: resource: Skip IRQ override on Asus Expertbook B2402CBA drm/amdkfd: Add sync after creating vram bo drm/amdkfd: Fix NULL pointer error for GC 11.0.1 on mGPU cifs: fix potential memory leaks in session setup spi: spidev: remove debug messages that access spidev->spi without locking KVM: s390: interrupt: use READ_ONCE() before cmpxchg() scsi: hisi_sas: Use abort task set to reset SAS disks when discovered scsi: hisi_sas: Set a port invalid only if there are no devices attached when refreshing port id r8152: add vendor/device ID pair for Microsoft Devkit platform/x86: touchscreen_dmi: Add info for the CSL Panther Tab HD platform/x86: asus-nb-wmi: Add alternate mapping for KEY_CAMERA platform/x86: asus-nb-wmi: Add alternate mapping for KEY_SCREENLOCK platform/x86: asus-wmi: Add quirk wmi_ignore_fan platform/x86: asus-wmi: Ignore fan on E410MA platform/x86: simatic-ipc: correct name of a model platform/x86: simatic-ipc: add another model lockref: stop doing cpu_relax in the cmpxchg loop ata: pata_cs5535: Don't build on UML firmware: coreboot: Check size of table entry and use flex-array btrfs: zoned: enable metadata over-commit for non-ZNS setup Revert "selftests/bpf: check null propagation only neither reg is PTR_TO_BTF_ID" arm64: efi: Recover from synchronous exceptions occurring in firmware arm64: efi: Avoid workqueue to check whether EFI runtime is live arm64: efi: Account for the EFI runtime stack in stack unwinder Bluetooth: hci_sync: cancel cmd_timer if hci_open failed drm/i915: Allow panel fixed modes to have differing sync polarities drm/i915: Allow alternate fixed modes always for eDP drm/amdgpu: complete gfxoff allow signal during suspend without delay io_uring/msg_ring: fix remote queue to disabled ring wifi: mac80211: Proper mark iTXQs for resumption wifi: mac80211: Fix iTXQ AMPDU fragmentation handling sched/fair: Check if prev_cpu has highest spare cap in feec() sched/uclamp: Fix a uninitialized variable warnings vfio/type1: Respect IOMMU reserved regions in vfio_test_domain_fgsp() scsi: hpsa: Fix allocation size for scsi_host_alloc() kvm/vfio: Fix potential deadlock on vfio group_lock nfsd: don't free files unconditionally in __nfsd_file_cache_purge module: Don't wait for GOING modules ftrace: Export ftrace_free_filter() to modules tracing: Make sure trace_printk() can output as soon as it can be used trace_events_hist: add check for return value of 'create_hist_field' ftrace/scripts: Update the instructions for ftrace-bisect.sh cifs: Fix oops due to uncleared server->smbd_conn in reconnect ksmbd: add max connections parameter ksmbd: do not sign response to session request for guest login ksmbd: downgrade ndr version error message to debug ksmbd: limit pdu length size according to connection status ovl: fix tmpfile leak ovl: fail on invalid uid/gid mapping at copy up io_uring/net: cache provided buffer group value for multishot receives KVM: x86/vmx: Do not skip segment attributes if unusable bit is set KVM: arm64: GICv4.1: Fix race with doorbell on VPE activation/deactivation scsi: ufs: core: Fix devfreq deadlocks riscv: fix -Wundef warning for CONFIG_RISCV_BOOT_SPINWAIT thermal: intel: int340x: Protect trip temperature from concurrent updates regulator: dt-bindings: samsung,s2mps14: add lost samsung,ext-control-gpios ipv6: fix reachability confirmation with proxy_ndp ARM: 9280/1: mm: fix warning on phys_addr_t to void pointer assignment EDAC/device: Respect any driver-supplied workqueue polling value EDAC/qcom: Do not pass llcc_driv_data as edac_device_ctl_info's pvt_info platform/x86: thinkpad_acpi: Fix profile modes on Intel platforms drm/display/dp_mst: Correct the kref of port. drm/amd/pm: add missing AllowIHInterrupt message mapping for SMU13.0.0 drm/amdgpu: remove unconditional trap enable on add gfx11 queues drm/amdgpu/display/mst: Fix mst_state->pbn_div and slot count assignments drm/amdgpu/display/mst: limit payload to be updated one by one drm/amdgpu/display/mst: update mst_mgr relevant variable when long HPD io_uring: inline io_req_task_work_add() io_uring: inline __io_req_complete_post() io_uring: hold locks for io_req_complete_failed io_uring: use io_req_task_complete() in timeout io_uring: remove io_req_tw_post_queue io_uring: inline __io_req_complete_put() net: mana: Fix IRQ name - add PCI and queue number io_uring: always prep_async for drain requests i2c: designware: use casting of u64 in clock multiplication to avoid overflow i2c: designware: Fix unbalanced suspended flag drm/drm_vma_manager: Add drm_vma_node_allow_once() drm/i915: Fix a memory leak with reused mmap_offset iavf: fix temporary deadlock and failure to set MAC address iavf: schedule watchdog immediately when changing primary MAC netlink: prevent potential spectre v1 gadgets net: fix UaF in netns ops registration error path net: fec: Use page_pool_put_full_page when freeing rx buffers nvme: simplify transport specific device attribute handling nvme: consolidate setting the tagset flags nvme-fc: fix initialization order drm/i915/selftest: fix intel_selftest_modify_policy argument types ACPI: video: Add backlight=native DMI quirk for HP Pavilion g6-1d80nr ACPI: video: Add backlight=native DMI quirk for HP EliteBook 8460p ACPI: video: Add backlight=native DMI quirk for Asus U46E netfilter: nft_set_rbtree: Switch to node list walk for overlap detection netfilter: nft_set_rbtree: skip elements in transaction from garbage collection netlink: annotate data races around nlk->portid netlink: annotate data races around dst_portid and dst_group netlink: annotate data races around sk_state ipv4: prevent potential spectre v1 gadget in ip_metrics_convert() ipv4: prevent potential spectre v1 gadget in fib_metrics_match() net: dsa: microchip: fix probe of I2C-connected KSZ8563 net: ethernet: adi: adin1110: Fix multicast offloading netfilter: conntrack: fix vtag checks for ABORT/SHUTDOWN_COMPLETE netrom: Fix use-after-free of a listening socket. platform/x86: asus-wmi: Fix kbd_dock_devid tablet-switch reporting platform/x86: apple-gmux: Move port defines to apple-gmux.h platform/x86: apple-gmux: Add apple_gmux_detect() helper ACPI: video: Fix apple gmux detection tracing/osnoise: Use built-in RCU list checking net/sched: sch_taprio: do not schedule in taprio_reset() sctp: fail if no bound addresses can be used for a given scope riscv/kprobe: Fix instruction simulation of JALR nvme: fix passthrough csi check gpio: mxc: Unlock on error path in mxc_flip_edge() gpio: ep93xx: Fix port F hwirq numbers in handler net: ravb: Fix lack of register setting after system resumed for Gen3 net: ravb: Fix possible hang if RIS2_QFF1 happen net: mctp: add an explicit reference from a mctp_sk_key to sock net: mctp: move expiry timer delete to unhash net: mctp: hold key reference when looking up a general key net: mctp: mark socks as dead on unhash, prevent re-add thermal: intel: int340x: Add locking to int340x_thermal_get_trip_type() riscv: Move call to init_cpu_topology() to later initialization stage net/tg3: resolve deadlock in tg3_reset_task() during EEH tsnep: Fix TX queue stop/wake for multiple queues net: mdio-mux-meson-g12a: force internal PHY off on mux switch Partially revert "perf/arm-cmn: Optimise DTC counter accesses" block: ublk: move ublk_chr_class destroying after devices are removed treewide: fix up files incorrectly marked executable tools: gpio: fix -c option of gpio-event-mon Fix up more non-executable files marked executable Revert "mm/compaction: fix set skip in fast_find_migrateblock" Revert "Input: synaptics - switch touchpad on HP Laptop 15-da3001TU to RMI mode" Input: i8042 - add Clevo PCX0DX to i8042 quirk table x86/sev: Add SEV-SNP guest feature negotiation support acpi: Fix suspend with Xen PV dt-bindings: riscv: fix underscore requirement for multi-letter extensions dt-bindings: riscv: fix single letter canonical order x86/i8259: Mark legacy PIC interrupts with IRQ_LEVEL dt-bindings: i2c: renesas,rzv2m: Fix SoC specific string netfilter: conntrack: unify established states for SCTP paths perf/x86/amd: fix potential integer overflow on shift of a int amdgpu: fix build on non-DCN platforms. Linux 6.1.9 Change-Id: I750dee519337922880b87841f6732565961c6b0a Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
1106 lines
26 KiB
C
1106 lines
26 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
*
|
|
* Copyright (C) 2011 Novell Inc.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/file.h>
|
|
#include <linux/fileattr.h>
|
|
#include <linux/splice.h>
|
|
#include <linux/xattr.h>
|
|
#include <linux/security.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/sched/signal.h>
|
|
#include <linux/cred.h>
|
|
#include <linux/namei.h>
|
|
#include <linux/fdtable.h>
|
|
#include <linux/ratelimit.h>
|
|
#include <linux/exportfs.h>
|
|
#include "overlayfs.h"
|
|
|
|
#define OVL_COPY_UP_CHUNK_SIZE (1 << 20)
|
|
|
|
static int ovl_ccup_set(const char *buf, const struct kernel_param *param)
|
|
{
|
|
pr_warn("\"check_copy_up\" module option is obsolete\n");
|
|
return 0;
|
|
}
|
|
|
|
static int ovl_ccup_get(char *buf, const struct kernel_param *param)
|
|
{
|
|
return sprintf(buf, "N\n");
|
|
}
|
|
|
|
module_param_call(check_copy_up, ovl_ccup_set, ovl_ccup_get, NULL, 0644);
|
|
MODULE_PARM_DESC(check_copy_up, "Obsolete; does nothing");
|
|
|
|
static bool ovl_must_copy_xattr(const char *name)
|
|
{
|
|
return !strcmp(name, XATTR_POSIX_ACL_ACCESS) ||
|
|
!strcmp(name, XATTR_POSIX_ACL_DEFAULT) ||
|
|
!strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN);
|
|
}
|
|
|
|
int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct dentry *new)
|
|
{
|
|
struct dentry *old = oldpath->dentry;
|
|
ssize_t list_size, size, value_size = 0;
|
|
char *buf, *name, *value = NULL;
|
|
int error = 0;
|
|
size_t slen;
|
|
|
|
if (!(old->d_inode->i_opflags & IOP_XATTR) ||
|
|
!(new->d_inode->i_opflags & IOP_XATTR))
|
|
return 0;
|
|
|
|
list_size = vfs_listxattr(old, NULL, 0);
|
|
if (list_size <= 0) {
|
|
if (list_size == -EOPNOTSUPP)
|
|
return 0;
|
|
return list_size;
|
|
}
|
|
|
|
buf = kvzalloc(list_size, GFP_KERNEL);
|
|
if (!buf)
|
|
return -ENOMEM;
|
|
|
|
list_size = vfs_listxattr(old, buf, list_size);
|
|
if (list_size <= 0) {
|
|
error = list_size;
|
|
goto out;
|
|
}
|
|
|
|
for (name = buf; list_size; name += slen) {
|
|
slen = strnlen(name, list_size) + 1;
|
|
|
|
/* underlying fs providing us with an broken xattr list? */
|
|
if (WARN_ON(slen > list_size)) {
|
|
error = -EIO;
|
|
break;
|
|
}
|
|
list_size -= slen;
|
|
|
|
if (ovl_is_private_xattr(sb, name))
|
|
continue;
|
|
|
|
error = security_inode_copy_up_xattr(name);
|
|
if (error < 0 && error != -EOPNOTSUPP)
|
|
break;
|
|
if (error == 1) {
|
|
error = 0;
|
|
continue; /* Discard */
|
|
}
|
|
retry:
|
|
size = ovl_do_getxattr(oldpath, name, value, value_size);
|
|
if (size == -ERANGE)
|
|
size = ovl_do_getxattr(oldpath, name, NULL, 0);
|
|
|
|
if (size < 0) {
|
|
error = size;
|
|
break;
|
|
}
|
|
|
|
if (size > value_size) {
|
|
void *new;
|
|
|
|
new = kvmalloc(size, GFP_KERNEL);
|
|
if (!new) {
|
|
error = -ENOMEM;
|
|
break;
|
|
}
|
|
kvfree(value);
|
|
value = new;
|
|
value_size = size;
|
|
goto retry;
|
|
}
|
|
|
|
error = ovl_do_setxattr(OVL_FS(sb), new, name, value, size, 0);
|
|
if (error) {
|
|
if (error != -EOPNOTSUPP || ovl_must_copy_xattr(name))
|
|
break;
|
|
|
|
/* Ignore failure to copy unknown xattrs */
|
|
error = 0;
|
|
}
|
|
}
|
|
kvfree(value);
|
|
out:
|
|
kvfree(buf);
|
|
return error;
|
|
}
|
|
|
|
static int ovl_copy_fileattr(struct inode *inode, const struct path *old,
|
|
const struct path *new)
|
|
{
|
|
struct fileattr oldfa = { .flags_valid = true };
|
|
struct fileattr newfa = { .flags_valid = true };
|
|
int err;
|
|
|
|
err = ovl_real_fileattr_get(old, &oldfa);
|
|
if (err) {
|
|
/* Ntfs-3g returns -EINVAL for "no fileattr support" */
|
|
if (err == -ENOTTY || err == -EINVAL)
|
|
return 0;
|
|
pr_warn("failed to retrieve lower fileattr (%pd2, err=%i)\n",
|
|
old->dentry, err);
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* We cannot set immutable and append-only flags on upper inode,
|
|
* because we would not be able to link upper inode to upper dir
|
|
* not set overlay private xattr on upper inode.
|
|
* Store these flags in overlay.protattr xattr instead.
|
|
*/
|
|
if (oldfa.flags & OVL_PROT_FS_FLAGS_MASK) {
|
|
err = ovl_set_protattr(inode, new->dentry, &oldfa);
|
|
if (err == -EPERM)
|
|
pr_warn_once("copying fileattr: no xattr on upper\n");
|
|
else if (err)
|
|
return err;
|
|
}
|
|
|
|
/* Don't bother copying flags if none are set */
|
|
if (!(oldfa.flags & OVL_COPY_FS_FLAGS_MASK))
|
|
return 0;
|
|
|
|
err = ovl_real_fileattr_get(new, &newfa);
|
|
if (err) {
|
|
/*
|
|
* Returning an error if upper doesn't support fileattr will
|
|
* result in a regression, so revert to the old behavior.
|
|
*/
|
|
if (err == -ENOTTY || err == -EINVAL) {
|
|
pr_warn_once("copying fileattr: no support on upper\n");
|
|
return 0;
|
|
}
|
|
pr_warn("failed to retrieve upper fileattr (%pd2, err=%i)\n",
|
|
new->dentry, err);
|
|
return err;
|
|
}
|
|
|
|
BUILD_BUG_ON(OVL_COPY_FS_FLAGS_MASK & ~FS_COMMON_FL);
|
|
newfa.flags &= ~OVL_COPY_FS_FLAGS_MASK;
|
|
newfa.flags |= (oldfa.flags & OVL_COPY_FS_FLAGS_MASK);
|
|
|
|
BUILD_BUG_ON(OVL_COPY_FSX_FLAGS_MASK & ~FS_XFLAG_COMMON);
|
|
newfa.fsx_xflags &= ~OVL_COPY_FSX_FLAGS_MASK;
|
|
newfa.fsx_xflags |= (oldfa.fsx_xflags & OVL_COPY_FSX_FLAGS_MASK);
|
|
|
|
return ovl_real_fileattr_set(new, &newfa);
|
|
}
|
|
|
|
static int ovl_copy_up_file(struct ovl_fs *ofs, struct dentry *dentry,
|
|
struct file *new_file, loff_t len)
|
|
{
|
|
struct path datapath;
|
|
struct file *old_file;
|
|
loff_t old_pos = 0;
|
|
loff_t new_pos = 0;
|
|
loff_t cloned;
|
|
loff_t data_pos = -1;
|
|
loff_t hole_len;
|
|
bool skip_hole = false;
|
|
int error = 0;
|
|
|
|
ovl_path_lowerdata(dentry, &datapath);
|
|
if (WARN_ON(datapath.dentry == NULL))
|
|
return -EIO;
|
|
|
|
old_file = ovl_path_open(&datapath, O_LARGEFILE | O_RDONLY);
|
|
if (IS_ERR(old_file))
|
|
return PTR_ERR(old_file);
|
|
|
|
/* Try to use clone_file_range to clone up within the same fs */
|
|
cloned = do_clone_file_range(old_file, 0, new_file, 0, len, 0);
|
|
if (cloned == len)
|
|
goto out_fput;
|
|
/* Couldn't clone, so now we try to copy the data */
|
|
|
|
/* Check if lower fs supports seek operation */
|
|
if (old_file->f_mode & FMODE_LSEEK)
|
|
skip_hole = true;
|
|
|
|
while (len) {
|
|
size_t this_len = OVL_COPY_UP_CHUNK_SIZE;
|
|
long bytes;
|
|
|
|
if (len < this_len)
|
|
this_len = len;
|
|
|
|
if (signal_pending_state(TASK_KILLABLE, current)) {
|
|
error = -EINTR;
|
|
break;
|
|
}
|
|
|
|
/*
|
|
* Fill zero for hole will cost unnecessary disk space
|
|
* and meanwhile slow down the copy-up speed, so we do
|
|
* an optimization for hole during copy-up, it relies
|
|
* on SEEK_DATA implementation in lower fs so if lower
|
|
* fs does not support it, copy-up will behave as before.
|
|
*
|
|
* Detail logic of hole detection as below:
|
|
* When we detect next data position is larger than current
|
|
* position we will skip that hole, otherwise we copy
|
|
* data in the size of OVL_COPY_UP_CHUNK_SIZE. Actually,
|
|
* it may not recognize all kind of holes and sometimes
|
|
* only skips partial of hole area. However, it will be
|
|
* enough for most of the use cases.
|
|
*/
|
|
|
|
if (skip_hole && data_pos < old_pos) {
|
|
data_pos = vfs_llseek(old_file, old_pos, SEEK_DATA);
|
|
if (data_pos > old_pos) {
|
|
hole_len = data_pos - old_pos;
|
|
len -= hole_len;
|
|
old_pos = new_pos = data_pos;
|
|
continue;
|
|
} else if (data_pos == -ENXIO) {
|
|
break;
|
|
} else if (data_pos < 0) {
|
|
skip_hole = false;
|
|
}
|
|
}
|
|
|
|
bytes = do_splice_direct(old_file, &old_pos,
|
|
new_file, &new_pos,
|
|
this_len, SPLICE_F_MOVE);
|
|
if (bytes <= 0) {
|
|
error = bytes;
|
|
break;
|
|
}
|
|
WARN_ON(old_pos != new_pos);
|
|
|
|
len -= bytes;
|
|
}
|
|
if (!error && ovl_should_sync(ofs))
|
|
error = vfs_fsync(new_file, 0);
|
|
out_fput:
|
|
fput(old_file);
|
|
return error;
|
|
}
|
|
|
|
static int ovl_set_size(struct ovl_fs *ofs,
|
|
struct dentry *upperdentry, struct kstat *stat)
|
|
{
|
|
struct iattr attr = {
|
|
.ia_valid = ATTR_SIZE,
|
|
.ia_size = stat->size,
|
|
};
|
|
|
|
return ovl_do_notify_change(ofs, upperdentry, &attr);
|
|
}
|
|
|
|
static int ovl_set_timestamps(struct ovl_fs *ofs, struct dentry *upperdentry,
|
|
struct kstat *stat)
|
|
{
|
|
struct iattr attr = {
|
|
.ia_valid =
|
|
ATTR_ATIME | ATTR_MTIME | ATTR_ATIME_SET | ATTR_MTIME_SET,
|
|
.ia_atime = stat->atime,
|
|
.ia_mtime = stat->mtime,
|
|
};
|
|
|
|
return ovl_do_notify_change(ofs, upperdentry, &attr);
|
|
}
|
|
|
|
int ovl_set_attr(struct ovl_fs *ofs, struct dentry *upperdentry,
|
|
struct kstat *stat)
|
|
{
|
|
int err = 0;
|
|
|
|
if (!S_ISLNK(stat->mode)) {
|
|
struct iattr attr = {
|
|
.ia_valid = ATTR_MODE,
|
|
.ia_mode = stat->mode,
|
|
};
|
|
err = ovl_do_notify_change(ofs, upperdentry, &attr);
|
|
}
|
|
if (!err) {
|
|
struct iattr attr = {
|
|
.ia_valid = ATTR_UID | ATTR_GID,
|
|
.ia_vfsuid = VFSUIDT_INIT(stat->uid),
|
|
.ia_vfsgid = VFSGIDT_INIT(stat->gid),
|
|
};
|
|
err = ovl_do_notify_change(ofs, upperdentry, &attr);
|
|
}
|
|
if (!err)
|
|
ovl_set_timestamps(ofs, upperdentry, stat);
|
|
|
|
return err;
|
|
}
|
|
|
|
struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
|
|
bool is_upper)
|
|
{
|
|
struct ovl_fh *fh;
|
|
int fh_type, dwords;
|
|
int buflen = MAX_HANDLE_SZ;
|
|
uuid_t *uuid = &real->d_sb->s_uuid;
|
|
int err;
|
|
|
|
/* Make sure the real fid stays 32bit aligned */
|
|
BUILD_BUG_ON(OVL_FH_FID_OFFSET % 4);
|
|
BUILD_BUG_ON(MAX_HANDLE_SZ + OVL_FH_FID_OFFSET > 255);
|
|
|
|
fh = kzalloc(buflen + OVL_FH_FID_OFFSET, GFP_KERNEL);
|
|
if (!fh)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
/*
|
|
* We encode a non-connectable file handle for non-dir, because we
|
|
* only need to find the lower inode number and we don't want to pay
|
|
* the price or reconnecting the dentry.
|
|
*/
|
|
dwords = buflen >> 2;
|
|
fh_type = exportfs_encode_fh(real, (void *)fh->fb.fid, &dwords, 0);
|
|
buflen = (dwords << 2);
|
|
|
|
err = -EIO;
|
|
if (WARN_ON(fh_type < 0) ||
|
|
WARN_ON(buflen > MAX_HANDLE_SZ) ||
|
|
WARN_ON(fh_type == FILEID_INVALID))
|
|
goto out_err;
|
|
|
|
fh->fb.version = OVL_FH_VERSION;
|
|
fh->fb.magic = OVL_FH_MAGIC;
|
|
fh->fb.type = fh_type;
|
|
fh->fb.flags = OVL_FH_FLAG_CPU_ENDIAN;
|
|
/*
|
|
* When we will want to decode an overlay dentry from this handle
|
|
* and all layers are on the same fs, if we get a disconncted real
|
|
* dentry when we decode fid, the only way to tell if we should assign
|
|
* it to upperdentry or to lowerstack is by checking this flag.
|
|
*/
|
|
if (is_upper)
|
|
fh->fb.flags |= OVL_FH_FLAG_PATH_UPPER;
|
|
fh->fb.len = sizeof(fh->fb) + buflen;
|
|
if (ofs->config.uuid)
|
|
fh->fb.uuid = *uuid;
|
|
|
|
return fh;
|
|
|
|
out_err:
|
|
kfree(fh);
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower,
|
|
struct dentry *upper)
|
|
{
|
|
const struct ovl_fh *fh = NULL;
|
|
int err;
|
|
|
|
/*
|
|
* When lower layer doesn't support export operations store a 'null' fh,
|
|
* so we can use the overlay.origin xattr to distignuish between a copy
|
|
* up and a pure upper inode.
|
|
*/
|
|
if (ovl_can_decode_fh(lower->d_sb)) {
|
|
fh = ovl_encode_real_fh(ofs, lower, false);
|
|
if (IS_ERR(fh))
|
|
return PTR_ERR(fh);
|
|
}
|
|
|
|
/*
|
|
* Do not fail when upper doesn't support xattrs.
|
|
*/
|
|
err = ovl_check_setxattr(ofs, upper, OVL_XATTR_ORIGIN, fh->buf,
|
|
fh ? fh->fb.len : 0, 0);
|
|
kfree(fh);
|
|
|
|
/* Ignore -EPERM from setting "user.*" on symlink/special */
|
|
return err == -EPERM ? 0 : err;
|
|
}
|
|
|
|
/* Store file handle of @upper dir in @index dir entry */
|
|
static int ovl_set_upper_fh(struct ovl_fs *ofs, struct dentry *upper,
|
|
struct dentry *index)
|
|
{
|
|
const struct ovl_fh *fh;
|
|
int err;
|
|
|
|
fh = ovl_encode_real_fh(ofs, upper, true);
|
|
if (IS_ERR(fh))
|
|
return PTR_ERR(fh);
|
|
|
|
err = ovl_setxattr(ofs, index, OVL_XATTR_UPPER, fh->buf, fh->fb.len);
|
|
|
|
kfree(fh);
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Create and install index entry.
|
|
*
|
|
* Caller must hold i_mutex on indexdir.
|
|
*/
|
|
static int ovl_create_index(struct dentry *dentry, struct dentry *origin,
|
|
struct dentry *upper)
|
|
{
|
|
struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
|
|
struct dentry *indexdir = ovl_indexdir(dentry->d_sb);
|
|
struct inode *dir = d_inode(indexdir);
|
|
struct dentry *index = NULL;
|
|
struct dentry *temp = NULL;
|
|
struct qstr name = { };
|
|
int err;
|
|
|
|
/*
|
|
* For now this is only used for creating index entry for directories,
|
|
* because non-dir are copied up directly to index and then hardlinked
|
|
* to upper dir.
|
|
*
|
|
* TODO: implement create index for non-dir, so we can call it when
|
|
* encoding file handle for non-dir in case index does not exist.
|
|
*/
|
|
if (WARN_ON(!d_is_dir(dentry)))
|
|
return -EIO;
|
|
|
|
/* Directory not expected to be indexed before copy up */
|
|
if (WARN_ON(ovl_test_flag(OVL_INDEX, d_inode(dentry))))
|
|
return -EIO;
|
|
|
|
err = ovl_get_index_name(ofs, origin, &name);
|
|
if (err)
|
|
return err;
|
|
|
|
temp = ovl_create_temp(ofs, indexdir, OVL_CATTR(S_IFDIR | 0));
|
|
err = PTR_ERR(temp);
|
|
if (IS_ERR(temp))
|
|
goto free_name;
|
|
|
|
err = ovl_set_upper_fh(ofs, upper, temp);
|
|
if (err)
|
|
goto out;
|
|
|
|
index = ovl_lookup_upper(ofs, name.name, indexdir, name.len);
|
|
if (IS_ERR(index)) {
|
|
err = PTR_ERR(index);
|
|
} else {
|
|
err = ovl_do_rename(ofs, dir, temp, dir, index, 0);
|
|
dput(index);
|
|
}
|
|
out:
|
|
if (err)
|
|
ovl_cleanup(ofs, dir, temp);
|
|
dput(temp);
|
|
free_name:
|
|
kfree(name.name);
|
|
return err;
|
|
}
|
|
|
|
struct ovl_copy_up_ctx {
|
|
struct dentry *parent;
|
|
struct dentry *dentry;
|
|
struct path lowerpath;
|
|
struct kstat stat;
|
|
struct kstat pstat;
|
|
const char *link;
|
|
struct dentry *destdir;
|
|
struct qstr destname;
|
|
struct dentry *workdir;
|
|
bool origin;
|
|
bool indexed;
|
|
bool metacopy;
|
|
};
|
|
|
|
static int ovl_link_up(struct ovl_copy_up_ctx *c)
|
|
{
|
|
int err;
|
|
struct dentry *upper;
|
|
struct dentry *upperdir = ovl_dentry_upper(c->parent);
|
|
struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
|
|
struct inode *udir = d_inode(upperdir);
|
|
|
|
/* Mark parent "impure" because it may now contain non-pure upper */
|
|
err = ovl_set_impure(c->parent, upperdir);
|
|
if (err)
|
|
return err;
|
|
|
|
err = ovl_set_nlink_lower(c->dentry);
|
|
if (err)
|
|
return err;
|
|
|
|
inode_lock_nested(udir, I_MUTEX_PARENT);
|
|
upper = ovl_lookup_upper(ofs, c->dentry->d_name.name, upperdir,
|
|
c->dentry->d_name.len);
|
|
err = PTR_ERR(upper);
|
|
if (!IS_ERR(upper)) {
|
|
err = ovl_do_link(ofs, ovl_dentry_upper(c->dentry), udir, upper);
|
|
dput(upper);
|
|
|
|
if (!err) {
|
|
/* Restore timestamps on parent (best effort) */
|
|
ovl_set_timestamps(ofs, upperdir, &c->pstat);
|
|
ovl_dentry_set_upper_alias(c->dentry);
|
|
}
|
|
}
|
|
inode_unlock(udir);
|
|
if (err)
|
|
return err;
|
|
|
|
err = ovl_set_nlink_upper(c->dentry);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int ovl_copy_up_data(struct ovl_copy_up_ctx *c, const struct path *temp)
|
|
{
|
|
struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
|
|
struct file *new_file;
|
|
int err;
|
|
|
|
if (!S_ISREG(c->stat.mode) || c->metacopy || !c->stat.size)
|
|
return 0;
|
|
|
|
new_file = ovl_path_open(temp, O_LARGEFILE | O_WRONLY);
|
|
if (IS_ERR(new_file))
|
|
return PTR_ERR(new_file);
|
|
|
|
err = ovl_copy_up_file(ofs, c->dentry, new_file, c->stat.size);
|
|
fput(new_file);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int ovl_copy_up_metadata(struct ovl_copy_up_ctx *c, struct dentry *temp)
|
|
{
|
|
struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
|
|
struct inode *inode = d_inode(c->dentry);
|
|
struct path upperpath = { .mnt = ovl_upper_mnt(ofs), .dentry = temp };
|
|
int err;
|
|
|
|
err = ovl_copy_xattr(c->dentry->d_sb, &c->lowerpath, temp);
|
|
if (err)
|
|
return err;
|
|
|
|
if (inode->i_flags & OVL_COPY_I_FLAGS_MASK) {
|
|
/*
|
|
* Copy the fileattr inode flags that are the source of already
|
|
* copied i_flags
|
|
*/
|
|
err = ovl_copy_fileattr(inode, &c->lowerpath, &upperpath);
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Store identifier of lower inode in upper inode xattr to
|
|
* allow lookup of the copy up origin inode.
|
|
*
|
|
* Don't set origin when we are breaking the association with a lower
|
|
* hard link.
|
|
*/
|
|
if (c->origin) {
|
|
err = ovl_set_origin(ofs, c->lowerpath.dentry, temp);
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
if (c->metacopy) {
|
|
err = ovl_check_setxattr(ofs, temp, OVL_XATTR_METACOPY,
|
|
NULL, 0, -EOPNOTSUPP);
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
inode_lock(temp->d_inode);
|
|
if (S_ISREG(c->stat.mode))
|
|
err = ovl_set_size(ofs, temp, &c->stat);
|
|
if (!err)
|
|
err = ovl_set_attr(ofs, temp, &c->stat);
|
|
inode_unlock(temp->d_inode);
|
|
|
|
return err;
|
|
}
|
|
|
|
struct ovl_cu_creds {
|
|
const struct cred *old;
|
|
struct cred *new;
|
|
};
|
|
|
|
static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)
|
|
{
|
|
int err;
|
|
|
|
cc->old = cc->new = NULL;
|
|
err = security_inode_copy_up(dentry, &cc->new);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
if (cc->new)
|
|
cc->old = override_creds(cc->new);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void ovl_revert_cu_creds(struct ovl_cu_creds *cc)
|
|
{
|
|
if (cc->new) {
|
|
revert_creds(cc->old);
|
|
put_cred(cc->new);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Copyup using workdir to prepare temp file. Used when copying up directories,
|
|
* special files or when upper fs doesn't support O_TMPFILE.
|
|
*/
|
|
static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)
|
|
{
|
|
struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
|
|
struct inode *inode;
|
|
struct inode *udir = d_inode(c->destdir), *wdir = d_inode(c->workdir);
|
|
struct path path = { .mnt = ovl_upper_mnt(ofs) };
|
|
struct dentry *temp, *upper;
|
|
struct ovl_cu_creds cc;
|
|
int err;
|
|
struct ovl_cattr cattr = {
|
|
/* Can't properly set mode on creation because of the umask */
|
|
.mode = c->stat.mode & S_IFMT,
|
|
.rdev = c->stat.rdev,
|
|
.link = c->link
|
|
};
|
|
|
|
/* workdir and destdir could be the same when copying up to indexdir */
|
|
err = -EIO;
|
|
if (lock_rename(c->workdir, c->destdir) != NULL)
|
|
goto unlock;
|
|
|
|
err = ovl_prep_cu_creds(c->dentry, &cc);
|
|
if (err)
|
|
goto unlock;
|
|
|
|
temp = ovl_create_temp(ofs, c->workdir, &cattr);
|
|
ovl_revert_cu_creds(&cc);
|
|
|
|
err = PTR_ERR(temp);
|
|
if (IS_ERR(temp))
|
|
goto unlock;
|
|
|
|
/*
|
|
* Copy up data first and then xattrs. Writing data after
|
|
* xattrs will remove security.capability xattr automatically.
|
|
*/
|
|
path.dentry = temp;
|
|
err = ovl_copy_up_data(c, &path);
|
|
if (err)
|
|
goto cleanup;
|
|
|
|
err = ovl_copy_up_metadata(c, temp);
|
|
if (err)
|
|
goto cleanup;
|
|
|
|
if (S_ISDIR(c->stat.mode) && c->indexed) {
|
|
err = ovl_create_index(c->dentry, c->lowerpath.dentry, temp);
|
|
if (err)
|
|
goto cleanup;
|
|
}
|
|
|
|
upper = ovl_lookup_upper(ofs, c->destname.name, c->destdir,
|
|
c->destname.len);
|
|
err = PTR_ERR(upper);
|
|
if (IS_ERR(upper))
|
|
goto cleanup;
|
|
|
|
err = ovl_do_rename(ofs, wdir, temp, udir, upper, 0);
|
|
dput(upper);
|
|
if (err)
|
|
goto cleanup;
|
|
|
|
if (!c->metacopy)
|
|
ovl_set_upperdata(d_inode(c->dentry));
|
|
inode = d_inode(c->dentry);
|
|
ovl_inode_update(inode, temp);
|
|
if (S_ISDIR(inode->i_mode))
|
|
ovl_set_flag(OVL_WHITEOUTS, inode);
|
|
unlock:
|
|
unlock_rename(c->workdir, c->destdir);
|
|
|
|
return err;
|
|
|
|
cleanup:
|
|
ovl_cleanup(ofs, wdir, temp);
|
|
dput(temp);
|
|
goto unlock;
|
|
}
|
|
|
|
/* Copyup using O_TMPFILE which does not require cross dir locking */
|
|
static int ovl_copy_up_tmpfile(struct ovl_copy_up_ctx *c)
|
|
{
|
|
struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
|
|
struct inode *udir = d_inode(c->destdir);
|
|
struct dentry *temp, *upper;
|
|
struct file *tmpfile;
|
|
struct ovl_cu_creds cc;
|
|
int err;
|
|
|
|
err = ovl_prep_cu_creds(c->dentry, &cc);
|
|
if (err)
|
|
return err;
|
|
|
|
tmpfile = ovl_do_tmpfile(ofs, c->workdir, c->stat.mode);
|
|
ovl_revert_cu_creds(&cc);
|
|
|
|
if (IS_ERR(tmpfile))
|
|
return PTR_ERR(tmpfile);
|
|
|
|
temp = tmpfile->f_path.dentry;
|
|
if (!c->metacopy && c->stat.size) {
|
|
err = ovl_copy_up_file(ofs, c->dentry, tmpfile, c->stat.size);
|
|
if (err)
|
|
goto out_fput;
|
|
}
|
|
|
|
err = ovl_copy_up_metadata(c, temp);
|
|
if (err)
|
|
goto out_fput;
|
|
|
|
inode_lock_nested(udir, I_MUTEX_PARENT);
|
|
|
|
upper = ovl_lookup_upper(ofs, c->destname.name, c->destdir,
|
|
c->destname.len);
|
|
err = PTR_ERR(upper);
|
|
if (!IS_ERR(upper)) {
|
|
err = ovl_do_link(ofs, temp, udir, upper);
|
|
dput(upper);
|
|
}
|
|
inode_unlock(udir);
|
|
|
|
if (err)
|
|
goto out_fput;
|
|
|
|
if (!c->metacopy)
|
|
ovl_set_upperdata(d_inode(c->dentry));
|
|
ovl_inode_update(d_inode(c->dentry), dget(temp));
|
|
|
|
out_fput:
|
|
fput(tmpfile);
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Copy up a single dentry
|
|
*
|
|
* All renames start with copy up of source if necessary. The actual
|
|
* rename will only proceed once the copy up was successful. Copy up uses
|
|
* upper parent i_mutex for exclusion. Since rename can change d_parent it
|
|
* is possible that the copy up will lock the old parent. At that point
|
|
* the file will have already been copied up anyway.
|
|
*/
|
|
static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
|
|
{
|
|
int err;
|
|
struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
|
|
bool to_index = false;
|
|
|
|
/*
|
|
* Indexed non-dir is copied up directly to the index entry and then
|
|
* hardlinked to upper dir. Indexed dir is copied up to indexdir,
|
|
* then index entry is created and then copied up dir installed.
|
|
* Copying dir up to indexdir instead of workdir simplifies locking.
|
|
*/
|
|
if (ovl_need_index(c->dentry)) {
|
|
c->indexed = true;
|
|
if (S_ISDIR(c->stat.mode))
|
|
c->workdir = ovl_indexdir(c->dentry->d_sb);
|
|
else
|
|
to_index = true;
|
|
}
|
|
|
|
if (S_ISDIR(c->stat.mode) || c->stat.nlink == 1 || to_index)
|
|
c->origin = true;
|
|
|
|
if (to_index) {
|
|
c->destdir = ovl_indexdir(c->dentry->d_sb);
|
|
err = ovl_get_index_name(ofs, c->lowerpath.dentry, &c->destname);
|
|
if (err)
|
|
return err;
|
|
} else if (WARN_ON(!c->parent)) {
|
|
/* Disconnected dentry must be copied up to index dir */
|
|
return -EIO;
|
|
} else {
|
|
/*
|
|
* Mark parent "impure" because it may now contain non-pure
|
|
* upper
|
|
*/
|
|
err = ovl_set_impure(c->parent, c->destdir);
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
/* Should we copyup with O_TMPFILE or with workdir? */
|
|
if (S_ISREG(c->stat.mode) && ofs->tmpfile)
|
|
err = ovl_copy_up_tmpfile(c);
|
|
else
|
|
err = ovl_copy_up_workdir(c);
|
|
if (err)
|
|
goto out;
|
|
|
|
if (c->indexed)
|
|
ovl_set_flag(OVL_INDEX, d_inode(c->dentry));
|
|
|
|
if (to_index) {
|
|
/* Initialize nlink for copy up of disconnected dentry */
|
|
err = ovl_set_nlink_upper(c->dentry);
|
|
} else {
|
|
struct inode *udir = d_inode(c->destdir);
|
|
|
|
/* Restore timestamps on parent (best effort) */
|
|
inode_lock(udir);
|
|
ovl_set_timestamps(ofs, c->destdir, &c->pstat);
|
|
inode_unlock(udir);
|
|
|
|
ovl_dentry_set_upper_alias(c->dentry);
|
|
}
|
|
|
|
out:
|
|
if (to_index)
|
|
kfree(c->destname.name);
|
|
return err;
|
|
}
|
|
|
|
static bool ovl_need_meta_copy_up(struct dentry *dentry, umode_t mode,
|
|
int flags)
|
|
{
|
|
struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
|
|
|
|
if (!ofs->config.metacopy)
|
|
return false;
|
|
|
|
if (!S_ISREG(mode))
|
|
return false;
|
|
|
|
if (flags && ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC)))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
static ssize_t ovl_getxattr_value(const struct path *path, char *name, char **value)
|
|
{
|
|
ssize_t res;
|
|
char *buf;
|
|
|
|
res = ovl_do_getxattr(path, name, NULL, 0);
|
|
if (res == -ENODATA || res == -EOPNOTSUPP)
|
|
res = 0;
|
|
|
|
if (res > 0) {
|
|
buf = kzalloc(res, GFP_KERNEL);
|
|
if (!buf)
|
|
return -ENOMEM;
|
|
|
|
res = ovl_do_getxattr(path, name, buf, res);
|
|
if (res < 0)
|
|
kfree(buf);
|
|
else
|
|
*value = buf;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
/* Copy up data of an inode which was copied up metadata only in the past. */
|
|
static int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c)
|
|
{
|
|
struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
|
|
struct path upperpath;
|
|
int err;
|
|
char *capability = NULL;
|
|
ssize_t cap_size;
|
|
|
|
ovl_path_upper(c->dentry, &upperpath);
|
|
if (WARN_ON(upperpath.dentry == NULL))
|
|
return -EIO;
|
|
|
|
if (c->stat.size) {
|
|
err = cap_size = ovl_getxattr_value(&upperpath, XATTR_NAME_CAPS,
|
|
&capability);
|
|
if (cap_size < 0)
|
|
goto out;
|
|
}
|
|
|
|
err = ovl_copy_up_data(c, &upperpath);
|
|
if (err)
|
|
goto out_free;
|
|
|
|
/*
|
|
* Writing to upper file will clear security.capability xattr. We
|
|
* don't want that to happen for normal copy-up operation.
|
|
*/
|
|
if (capability) {
|
|
err = ovl_do_setxattr(ofs, upperpath.dentry, XATTR_NAME_CAPS,
|
|
capability, cap_size, 0);
|
|
if (err)
|
|
goto out_free;
|
|
}
|
|
|
|
|
|
err = ovl_removexattr(ofs, upperpath.dentry, OVL_XATTR_METACOPY);
|
|
if (err)
|
|
goto out_free;
|
|
|
|
ovl_set_upperdata(d_inode(c->dentry));
|
|
out_free:
|
|
kfree(capability);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
|
|
int flags)
|
|
{
|
|
int err;
|
|
DEFINE_DELAYED_CALL(done);
|
|
struct path parentpath;
|
|
struct ovl_copy_up_ctx ctx = {
|
|
.parent = parent,
|
|
.dentry = dentry,
|
|
.workdir = ovl_workdir(dentry),
|
|
};
|
|
|
|
if (WARN_ON(!ctx.workdir))
|
|
return -EROFS;
|
|
|
|
ovl_path_lower(dentry, &ctx.lowerpath);
|
|
err = vfs_getattr(&ctx.lowerpath, &ctx.stat,
|
|
STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
|
|
if (err)
|
|
return err;
|
|
|
|
if (!kuid_has_mapping(current_user_ns(), ctx.stat.uid) ||
|
|
!kgid_has_mapping(current_user_ns(), ctx.stat.gid))
|
|
return -EOVERFLOW;
|
|
|
|
ctx.metacopy = ovl_need_meta_copy_up(dentry, ctx.stat.mode, flags);
|
|
|
|
if (parent) {
|
|
ovl_path_upper(parent, &parentpath);
|
|
ctx.destdir = parentpath.dentry;
|
|
ctx.destname = dentry->d_name;
|
|
|
|
err = vfs_getattr(&parentpath, &ctx.pstat,
|
|
STATX_ATIME | STATX_MTIME,
|
|
AT_STATX_SYNC_AS_STAT);
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
/* maybe truncate regular file. this has no effect on dirs */
|
|
if (flags & O_TRUNC)
|
|
ctx.stat.size = 0;
|
|
|
|
if (S_ISLNK(ctx.stat.mode)) {
|
|
ctx.link = vfs_get_link(ctx.lowerpath.dentry, &done);
|
|
if (IS_ERR(ctx.link))
|
|
return PTR_ERR(ctx.link);
|
|
}
|
|
|
|
err = ovl_copy_up_start(dentry, flags);
|
|
/* err < 0: interrupted, err > 0: raced with another copy-up */
|
|
if (unlikely(err)) {
|
|
if (err > 0)
|
|
err = 0;
|
|
} else {
|
|
if (!ovl_dentry_upper(dentry))
|
|
err = ovl_do_copy_up(&ctx);
|
|
if (!err && parent && !ovl_dentry_has_upper_alias(dentry))
|
|
err = ovl_link_up(&ctx);
|
|
if (!err && ovl_dentry_needs_data_copy_up_locked(dentry, flags))
|
|
err = ovl_copy_up_meta_inode_data(&ctx);
|
|
ovl_copy_up_end(dentry);
|
|
}
|
|
do_delayed_call(&done);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int ovl_copy_up_flags(struct dentry *dentry, int flags)
|
|
{
|
|
int err = 0;
|
|
const struct cred *old_cred;
|
|
bool disconnected = (dentry->d_flags & DCACHE_DISCONNECTED);
|
|
|
|
/*
|
|
* With NFS export, copy up can get called for a disconnected non-dir.
|
|
* In this case, we will copy up lower inode to index dir without
|
|
* linking it to upper dir.
|
|
*/
|
|
if (WARN_ON(disconnected && d_is_dir(dentry)))
|
|
return -EIO;
|
|
|
|
old_cred = ovl_override_creds(dentry->d_sb);
|
|
while (!err) {
|
|
struct dentry *next;
|
|
struct dentry *parent = NULL;
|
|
|
|
if (ovl_already_copied_up(dentry, flags))
|
|
break;
|
|
|
|
next = dget(dentry);
|
|
/* find the topmost dentry not yet copied up */
|
|
for (; !disconnected;) {
|
|
parent = dget_parent(next);
|
|
|
|
if (ovl_dentry_upper(parent))
|
|
break;
|
|
|
|
dput(next);
|
|
next = parent;
|
|
}
|
|
|
|
err = ovl_copy_up_one(parent, next, flags);
|
|
|
|
dput(parent);
|
|
dput(next);
|
|
}
|
|
ovl_revert_creds(dentry->d_sb, old_cred);
|
|
|
|
return err;
|
|
}
|
|
|
|
static bool ovl_open_need_copy_up(struct dentry *dentry, int flags)
|
|
{
|
|
/* Copy up of disconnected dentry does not set upper alias */
|
|
if (ovl_already_copied_up(dentry, flags))
|
|
return false;
|
|
|
|
if (special_file(d_inode(dentry)->i_mode))
|
|
return false;
|
|
|
|
if (!ovl_open_flags_need_copy_up(flags))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
int ovl_maybe_copy_up(struct dentry *dentry, int flags)
|
|
{
|
|
int err = 0;
|
|
|
|
if (ovl_open_need_copy_up(dentry, flags)) {
|
|
err = ovl_want_write(dentry);
|
|
if (!err) {
|
|
err = ovl_copy_up_flags(dentry, flags);
|
|
ovl_drop_write(dentry);
|
|
}
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
int ovl_copy_up_with_data(struct dentry *dentry)
|
|
{
|
|
return ovl_copy_up_flags(dentry, O_WRONLY);
|
|
}
|
|
|
|
int ovl_copy_up(struct dentry *dentry)
|
|
{
|
|
return ovl_copy_up_flags(dentry, 0);
|
|
}
|