9100d24dfd
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmYaZdgACgkQONu9yGCS aT4oMxAA0pATFAq8RN5f9CmYlMg5HqHgzZ8lJv8P0/reOINhUa+F5sJb1n+x+Ch4 WQbmiFeZRzfsKZ2qKhIdNR0Lg+9JOr/DtYXdSBZ6InfSWrTAIrQ9fjl5Warkmcgg O4WbgF5BVgU3vGFATgxLvnUZwhR1D7WK93oMDunzrT7+OqyncU3f1Uj53ZAu9030 z18UNqnTxDLYH/CMGwAeRkaZqBev9gZ1HdgQWA27SVLqWQwZq0al81Cmlo+ECVmk 5dF6V2pid4qfKGJjDDfx1NS0PVnoP68iK4By1SXyoFV9VBiSwp77nUUyDr7YsHsT u8GpZHr9jZvSO5/xtKv20NPLejTPCRKc06CbkwpikDRtGOocBL8em0GuVqlf8hMs KwDb6ZEzYhXZGPJHbJM+aRD1tq/KHw9X7TrldOszMQPr6lubBtscPbg1FCg3OlcC HUrtub0i275x7TH0dJeRTD8TRE9jRmF+tl7KQytEJM3JRrquFjLyhDj+/VJnZkiB lzj3FRf4zshzgz4+CAeqXO/8Lu8b3fGYmcW1acCmk7emjDcXUKojPj/Aig6T4l7P oCWDY3+w1E6eiyE8BazxY1KUa/41ld0VJnlW5JWGRaDFTJwrk0h6/rvf9qImSckw IGx24UezRyp6NS1op3Qm2iwHLr41pFRfKxNm9ppgH9iBPzOhe38= =pkLL -----END PGP SIGNATURE----- Merge 5.10.215 into android12-5.10-lts Changes in 5.10.215 amdkfd: use calloc instead of kzalloc to avoid integer overflow Documentation/hw-vuln: Update spectre doc x86/cpu: Support AMD Automatic IBRS x86/bugs: Use sysfs_emit() timers: Update kernel-doc for various functions timers: Use del_timer_sync() even on UP timers: Rename del_timer_sync() to timer_delete_sync() wifi: brcmfmac: Fix use-after-free bug in brcmf_cfg80211_detach media: staging: ipu3-imgu: Set fields before media_entity_pads_init() clk: qcom: gcc-sdm845: Add soft dependency on rpmhpd smack: Set SMACK64TRANSMUTE only for dirs in smack_inode_setxattr() smack: Handle SMACK64TRANSMUTE in smack_inode_setsecurity() arm: dts: marvell: Fix maxium->maxim typo in brownstone dts drm/vmwgfx: stop using ttm_bo_create v2 drm/vmwgfx: switch over to the new pin interface v2 drm/vmwgfx/vmwgfx_cmdbuf_res: Remove unused variable 'ret' drm/vmwgfx: Fix some static checker warnings drm/vmwgfx: Fix possible null pointer derefence with invalid contexts serial: max310x: fix NULL pointer dereference in I2C instantiation media: xc4000: Fix atomicity violation in xc4000_get_frequency KVM: Always flush async #PF workqueue when vCPU is being destroyed sparc64: NMI watchdog: fix return value of __setup handler sparc: vDSO: fix return value of __setup handler crypto: qat - fix double free during reset crypto: qat - resolve race condition during AER recovery selftests/mqueue: Set timeout to 180 seconds ext4: correct best extent lstart adjustment logic block: introduce zone_write_granularity limit block: Clear zone limits for a non-zoned stacked queue bounds: support non-power-of-two CONFIG_NR_CPUS fat: fix uninitialized field in nostale filehandles ubifs: Set page uptodate in the correct place ubi: Check for too small LEB size in VTBL code ubi: correct the calculation of fastmap size mtd: rawnand: meson: fix scrambling mode value in command macro parisc: Avoid clobbering the C/B bits in the PSW with tophys and tovirt macros parisc: Fix ip_fast_csum parisc: Fix csum_ipv6_magic on 32-bit systems parisc: Fix csum_ipv6_magic on 64-bit systems parisc: Strip upper 32 bit of sum in csum_ipv6_magic for 64-bit builds PM: suspend: Set mem_sleep_current during kernel command line setup clk: qcom: gcc-ipq6018: fix terminating of frequency table arrays clk: qcom: gcc-ipq8074: fix terminating of frequency table arrays clk: qcom: mmcc-apq8084: fix terminating of frequency table arrays clk: qcom: mmcc-msm8974: fix terminating of frequency table arrays powerpc/fsl: Fix mfpmr build errors with newer binutils USB: serial: ftdi_sio: add support for GMC Z216C Adapter IR-USB USB: serial: add device ID for VeriFone adapter USB: serial: cp210x: add ID for MGP Instruments PDS100 USB: serial: option: add MeiG Smart SLM320 product USB: serial: cp210x: add pid/vid for TDK NC0110013M and MM0110113M PM: sleep: wakeirq: fix wake irq warning in system suspend mmc: tmio: avoid concurrent runs of mmc_request_done() fuse: fix root lookup with nonzero generation fuse: don't unhash root usb: typec: ucsi: Clean up UCSI_CABLE_PROP macros printk/console: Split out code that enables default console serial: Lock console when calling into driver before registration btrfs: fix off-by-one chunk length calculation at contains_pending_extent() PCI: Drop pci_device_remove() test of pci_dev->driver PCI/PM: Drain runtime-idle callbacks before driver removal PCI/ERR: Cache RCEC EA Capability offset in pci_init_capabilities() PCI: Cache PCIe Device Capabilities register PCI: Work around Intel I210 ROM BAR overlap defect PCI/ASPM: Make Intel DG2 L1 acceptable latency unlimited PCI/DPC: Quirk PIO log size for certain Intel Root Ports PCI/DPC: Quirk PIO log size for Intel Raptor Lake Root Ports Revert "Revert "md/raid5: Wait for MD_SB_CHANGE_PENDING in raid5d"" dm-raid: fix lockdep waring in "pers->hot_add_disk" mac802154: fix llsec key resources release in mac802154_llsec_key_del mm: swap: fix race between free_swap_and_cache() and swapoff() mmc: core: Fix switch on gp3 partition drm/etnaviv: Restore some id values hwmon: (amc6821) add of_match table ext4: fix corruption during on-line resize nvmem: meson-efuse: fix function pointer type mismatch slimbus: core: Remove usage of the deprecated ida_simple_xx() API phy: tegra: xusb: Add API to retrieve the port number of phy usb: gadget: tegra-xudc: Use dev_err_probe() usb: gadget: tegra-xudc: Fix USB3 PHY retrieval logic speakup: Fix 8bit characters from direct synth PCI/ERR: Clear AER status only when we control AER PCI/AER: Block runtime suspend when handling errors nfs: fix UAF in direct writes kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1 PCI: dwc: endpoint: Fix advertised resizable BAR size vfio/platform: Disable virqfds on cleanup ring-buffer: Fix waking up ring buffer readers ring-buffer: Do not set shortest_full when full target is hit ring-buffer: Fix resetting of shortest_full ring-buffer: Fix full_waiters_pending in poll soc: fsl: qbman: Always disable interrupts when taking cgr_lock soc: fsl: qbman: Add helper for sanity checking cgr ops soc: fsl: qbman: Add CGR update function soc: fsl: qbman: Use raw spinlock for cgr_lock s390/zcrypt: fix reference counting on zcrypt card objects drm/panel: do not return negative error codes from drm_panel_get_modes() drm/exynos: do not return negative values from .get_modes() drm/imx/ipuv3: do not return negative values from .get_modes() drm/vc4: hdmi: do not return negative values from .get_modes() memtest: use {READ,WRITE}_ONCE in memory scanning nilfs2: fix failure to detect DAT corruption in btree and direct mappings nilfs2: prevent kernel bug at submit_bh_wbc() cpufreq: dt: always allocate zeroed cpumask x86/CPU/AMD: Update the Zenbleed microcode revisions net: hns3: tracing: fix hclgevf trace event strings wireguard: netlink: check for dangling peer via is_dead instead of empty list wireguard: netlink: access device through ctx instead of peer ahci: asm1064: correct count of reported ports ahci: asm1064: asm1166: don't limit reported ports drm/amd/display: Return the correct HDCP error code drm/amd/display: Fix noise issue on HDMI AV mute dm snapshot: fix lockup in dm_exception_table_exit vxge: remove unnecessary cast in kfree() x86/stackprotector/32: Make the canary into a regular percpu variable x86/pm: Work around false positive kmemleak report in msr_build_context() scripts: kernel-doc: Fix syntax error due to undeclared args variable comedi: comedi_test: Prevent timers rescheduling during deletion cpufreq: brcmstb-avs-cpufreq: fix up "add check for cpufreq_cpu_get's return value" netfilter: nf_tables: mark set as dead when unbinding anonymous set with timeout netfilter: nf_tables: disallow anonymous set with timeout flag netfilter: nf_tables: reject constant set with timeout Drivers: hv: vmbus: Calculate ring buffer size for more efficient use of memory xfrm: Avoid clang fortify warning in copy_to_user_tmpl() KVM: SVM: Flush pages under kvm->lock to fix UAF in svm_register_enc_region() ALSA: hda/realtek - Fix headset Mic no show at resume back for Lenovo ALC897 platform USB: usb-storage: Prevent divide-by-0 error in isd200_ata_command usb: gadget: ncm: Fix handling of zero block length packets usb: port: Don't try to peer unused USB ports based on location tty: serial: fsl_lpuart: avoid idle preamble pending if CTS is enabled mei: me: add arrow lake point S DID mei: me: add arrow lake point H DID vt: fix unicode buffer corruption when deleting characters fs/aio: Check IOCB_AIO_RW before the struct aio_kiocb conversion tee: optee: Fix kernel panic caused by incorrect error handling xen/events: close evtchn after mapping cleanup printk: Update @console_may_schedule in console_trylock_spinning() btrfs: allocate btrfs_ioctl_defrag_range_args on stack x86/asm: Add _ASM_RIP() macro for x86-64 (%rip) suffix x86/bugs: Add asm helpers for executing VERW x86/entry_64: Add VERW just before userspace transition x86/entry_32: Add VERW just before userspace transition x86/bugs: Use ALTERNATIVE() instead of mds_user_clear static key KVM/VMX: Use BT+JNC, i.e. EFLAGS.CF to select VMRESUME vs. VMLAUNCH KVM/VMX: Move VERW closer to VMentry for MDS mitigation x86/mmio: Disable KVM mitigation when X86_FEATURE_CLEAR_CPU_BUF is set Documentation/hw-vuln: Add documentation for RFDS x86/rfds: Mitigate Register File Data Sampling (RFDS) KVM/x86: Export RFDS_NO and RFDS_CLEAR to guests perf/core: Fix reentry problem in perf_output_read_group() efivarfs: Request at most 512 bytes for variable names powerpc: xor_vmx: Add '-mhard-float' to CFLAGS serial: sc16is7xx: convert from _raw_ to _noinc_ regmap functions for FIFO mm/memory-failure: fix an incorrect use of tail pages mm/migrate: set swap entry values of THP tail pages properly. init: open /initrd.image with O_LARGEFILE wifi: mac80211: check/clear fast rx for non-4addr sta VLAN changes exec: Fix NOMMU linux_binprm::exec in transfer_args_to_stack() hexagon: vmlinux.lds.S: handle attributes section mmc: core: Initialize mmc_blk_ioc_data mmc: core: Avoid negative index with array access net: ll_temac: platform_get_resource replaced by wrong function usb: cdc-wdm: close race between read and workqueue ALSA: sh: aica: reorder cleanup operations to avoid UAF bugs scsi: core: Fix unremoved procfs host directory regression staging: vc04_services: changen strncpy() to strscpy_pad() staging: vc04_services: fix information leak in create_component() USB: core: Add hub_get() and hub_put() routines usb: dwc2: host: Fix remote wakeup from hibernation usb: dwc2: host: Fix hibernation flow usb: dwc2: host: Fix ISOC flow in DDMA mode usb: dwc2: gadget: LPM flow fix usb: udc: remove warning when queue disabled ep usb: typec: ucsi: Ack unsupported commands usb: typec: ucsi: Clear UCSI_CCI_RESET_COMPLETE before reset scsi: qla2xxx: Split FCE|EFT trace control scsi: qla2xxx: Fix command flush on cable pull scsi: qla2xxx: Delay I/O Abort on PCI error x86/cpu: Enable STIBP on AMD if Automatic IBRS is enabled PCI/DPC: Quirk PIO log size for Intel Ice Lake Root Ports scsi: lpfc: Correct size for wqe for memset() USB: core: Fix deadlock in usb_deauthorize_interface() nfc: nci: Fix uninit-value in nci_dev_up and nci_ntf_packet ixgbe: avoid sleeping allocation in ixgbe_ipsec_vf_add_sa() tcp: properly terminate timers for kernel sockets ACPICA: debugger: check status of acpi_evaluate_object() in acpi_db_walk_for_fields() bpf: Protect against int overflow for stack access size Octeontx2-af: fix pause frame configuration in GMP mode dm integrity: fix out-of-range warning r8169: fix issue caused by buggy BIOS on certain boards with RTL8168d x86/cpufeatures: Add new word for scattered features Bluetooth: hci_event: set the conn encrypted before conn establishes Bluetooth: Fix TOCTOU in HCI debugfs implementation netfilter: nf_tables: disallow timeout for anonymous sets net/rds: fix possible cp null dereference vfio/pci: Disable auto-enable of exclusive INTx IRQ vfio/pci: Lock external INTx masking ops vfio: Introduce interface to flush virqfd inject workqueue vfio/pci: Create persistent INTx handler vfio/platform: Create persistent IRQ handlers vfio/fsl-mc: Block calling interrupt handler without trigger io_uring: ensure '0' is returned on file registration success Revert "x86/mm/ident_map: Use gbpages only where full GB page should be mapped." mm, vmscan: prevent infinite loop for costly GFP_NOIO | __GFP_RETRY_MAYFAIL allocations x86/srso: Add SRSO mitigation for Hygon processors block: add check that partition length needs to be aligned with block size netfilter: nf_tables: reject new basechain after table flag update netfilter: nf_tables: flush pending destroy work before exit_net release netfilter: nf_tables: Fix potential data-race in __nft_flowtable_type_get() netfilter: validate user input for expected length vboxsf: Avoid an spurious warning if load_nls_xxx() fails bpf, sockmap: Prevent lock inversion deadlock in map delete elem net/sched: act_skbmod: prevent kernel-infoleak net: stmmac: fix rx queue priority assignment erspan: make sure erspan_base_hdr is present in skb->head selftests: reuseaddr_conflict: add missing new line at the end of the output ipv6: Fix infinite recursion in fib6_dump_done(). udp: do not transition UDP GRO fraglist partial checksums to unnecessary octeontx2-pf: check negative error code in otx2_open() i40e: fix i40e_count_filters() to count only active/new filters i40e: fix vf may be used uninitialized in this function warning scsi: qla2xxx: Update manufacturer details scsi: qla2xxx: Update manufacturer detail Revert "usb: phy: generic: Get the vbus supply" udp: do not accept non-tunnel GSO skbs landing in a tunnel net: ravb: Always process TX descriptor ring arm64: dts: qcom: sc7180: Remove clock for bluetooth on Trogdor arm64: dts: qcom: sc7180-trogdor: mark bluetooth address as broken ASoC: ops: Fix wraparound for mask in snd_soc_get_volsw ata: sata_sx4: fix pdc20621_get_from_dimm() on 64-bit scsi: mylex: Fix sysfs buffer lengths ata: sata_mv: Fix PCI device ID table declaration compilation warning ALSA: hda/realtek: Update Panasonic CF-SZ6 quirk to support headset with microphone driver core: Introduce device_link_wait_removal() of: dynamic: Synchronize of_changeset_destroy() with the devlink removals x86/mce: Make sure to grab mce_sysfs_mutex in set_bank() s390/entry: align system call table on 8 bytes riscv: Fix spurious errors from __get/put_kernel_nofault x86/bugs: Fix the SRSO mitigation on Zen3/4 x86/retpoline: Do the necessary fixup to the Zen3/4 srso return thunk for !SRSO mptcp: don't account accept() of non-MPC client as fallback to TCP x86/cpufeatures: Add CPUID_LNX_5 to track recently added Linux-defined word objtool: Add asm version of STACK_FRAME_NON_STANDARD wifi: ath9k: fix LNA selection in ath_ant_try_scan() VMCI: Fix memcpy() run-time warning in dg_dispatch_as_host() panic: Flush kernel log buffer at the end arm64: dts: rockchip: fix rk3328 hdmi ports node arm64: dts: rockchip: fix rk3399 hdmi ports node ionic: set adminq irq affinity pstore/zone: Add a null pointer check to the psz_kmsg_read tools/power x86_energy_perf_policy: Fix file leak in get_pkg_num() btrfs: handle chunk tree lookup error in btrfs_relocate_sys_chunks() btrfs: export: handle invalid inode or root reference in btrfs_get_parent() btrfs: send: handle path ref underflow in header iterate_inode_ref() net/smc: reduce rtnl pressure in smc_pnet_create_pnetids_list() Bluetooth: btintel: Fix null ptr deref in btintel_read_version Input: synaptics-rmi4 - fail probing if memory allocation for "phys" fails pinctrl: renesas: checker: Limit cfg reg enum checks to provided IDs sysv: don't call sb_bread() with pointers_lock held scsi: lpfc: Fix possible memory leak in lpfc_rcv_padisc() isofs: handle CDs with bad root inode but good Joliet root directory media: sta2x11: fix irq handler cast ext4: add a hint for block bitmap corrupt state in mb_groups ext4: forbid commit inconsistent quota data when errors=remount-ro drm/amd/display: Fix nanosec stat overflow SUNRPC: increase size of rpc_wait_queue.qlen from unsigned short to unsigned int Revert "ACPI: PM: Block ASUS B1400CEAE from suspend to idle by default" libperf evlist: Avoid out-of-bounds access block: prevent division by zero in blk_rq_stat_sum() RDMA/cm: add timeout to cm_destroy_id wait Input: allocate keycode for Display refresh rate toggle platform/x86: touchscreen_dmi: Add an extra entry for a variant of the Chuwi Vi8 tablet ktest: force $buildonly = 1 for 'make_warnings_file' test type ring-buffer: use READ_ONCE() to read cpu_buffer->commit_page in concurrent environment tools: iio: replace seekdir() in iio_generic_buffer usb: typec: tcpci: add generic tcpci fallback compatible usb: sl811-hcd: only defined function checkdone if QUIRK2 is defined fbdev: viafb: fix typo in hw_bitblt_1 and hw_bitblt_2 drivers/nvme: Add quirks for device 126f:2262 fbmon: prevent division by zero in fb_videomode_from_videomode() netfilter: nf_tables: release batch on table validation from abort path netfilter: nf_tables: release mutex after nft_gc_seq_end from abort path netfilter: nf_tables: discard table flag update with pending basechain deletion tty: n_gsm: require CAP_NET_ADMIN to attach N_GSM0710 ldisc virtio: reenable config if freezing device failed x86/mm/pat: fix VM_PAT handling in COW mappings drm/i915/gt: Reset queue_priority_hint on parking Bluetooth: btintel: Fixe build regression VMCI: Fix possible memcpy() run-time warning in vmci_datagram_invoke_guest_handler() kbuild: dummy-tools: adjust to stricter stackprotector check scsi: sd: Fix wrong zone_write_granularity value during revalidate x86/retpoline: Add NOENDBR annotation to the SRSO dummy return thunk x86/head/64: Re-enable stack protection Linux 5.10.215 Change-Id: I45a0a9c4a0683ff5ef97315690f1f884f666e1b5 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
711 lines
17 KiB
C
711 lines
17 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/capability.h>
|
|
#include <linux/compat.h>
|
|
#include <linux/blkdev.h>
|
|
#include <linux/export.h>
|
|
#include <linux/gfp.h>
|
|
#include <linux/blkpg.h>
|
|
#include <linux/hdreg.h>
|
|
#include <linux/backing-dev.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/blktrace_api.h>
|
|
#include <linux/pr.h>
|
|
#include <linux/uaccess.h>
|
|
#include "blk.h"
|
|
|
|
static int blkpg_do_ioctl(struct block_device *bdev,
|
|
struct blkpg_partition __user *upart, int op)
|
|
{
|
|
struct blkpg_partition p;
|
|
sector_t start, length;
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EACCES;
|
|
if (copy_from_user(&p, upart, sizeof(struct blkpg_partition)))
|
|
return -EFAULT;
|
|
if (bdev_is_partition(bdev))
|
|
return -EINVAL;
|
|
|
|
if (p.pno <= 0)
|
|
return -EINVAL;
|
|
|
|
if (op == BLKPG_DEL_PARTITION)
|
|
return bdev_del_partition(bdev, p.pno);
|
|
|
|
if (p.start < 0 || p.length <= 0 || p.start + p.length < 0)
|
|
return -EINVAL;
|
|
/* Check that the partition is aligned to the block size */
|
|
if (!IS_ALIGNED(p.start | p.length, bdev_logical_block_size(bdev)))
|
|
return -EINVAL;
|
|
|
|
start = p.start >> SECTOR_SHIFT;
|
|
length = p.length >> SECTOR_SHIFT;
|
|
|
|
/* check for fit in a hd_struct */
|
|
if (sizeof(sector_t) < sizeof(long long)) {
|
|
long pstart = start, plength = length;
|
|
|
|
if (pstart != start || plength != length || pstart < 0 ||
|
|
plength < 0 || p.pno > 65535)
|
|
return -EINVAL;
|
|
}
|
|
|
|
switch (op) {
|
|
case BLKPG_ADD_PARTITION:
|
|
return bdev_add_partition(bdev, p.pno, start, length);
|
|
case BLKPG_RESIZE_PARTITION:
|
|
return bdev_resize_partition(bdev, p.pno, start, length);
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
static int blkpg_ioctl(struct block_device *bdev,
|
|
struct blkpg_ioctl_arg __user *arg)
|
|
{
|
|
struct blkpg_partition __user *udata;
|
|
int op;
|
|
|
|
if (get_user(op, &arg->op) || get_user(udata, &arg->data))
|
|
return -EFAULT;
|
|
|
|
return blkpg_do_ioctl(bdev, udata, op);
|
|
}
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
struct compat_blkpg_ioctl_arg {
|
|
compat_int_t op;
|
|
compat_int_t flags;
|
|
compat_int_t datalen;
|
|
compat_caddr_t data;
|
|
};
|
|
|
|
static int compat_blkpg_ioctl(struct block_device *bdev,
|
|
struct compat_blkpg_ioctl_arg __user *arg)
|
|
{
|
|
compat_caddr_t udata;
|
|
int op;
|
|
|
|
if (get_user(op, &arg->op) || get_user(udata, &arg->data))
|
|
return -EFAULT;
|
|
|
|
return blkpg_do_ioctl(bdev, compat_ptr(udata), op);
|
|
}
|
|
#endif
|
|
|
|
static int blkdev_reread_part(struct block_device *bdev, fmode_t mode)
|
|
{
|
|
struct block_device *tmp;
|
|
|
|
if (!disk_part_scan_enabled(bdev->bd_disk) || bdev_is_partition(bdev))
|
|
return -EINVAL;
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EACCES;
|
|
if (bdev->bd_part_count)
|
|
return -EBUSY;
|
|
|
|
/*
|
|
* Reopen the device to revalidate the driver state and force a
|
|
* partition rescan.
|
|
*/
|
|
mode &= ~FMODE_EXCL;
|
|
set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
|
|
|
|
tmp = blkdev_get_by_dev(bdev->bd_dev, mode, NULL);
|
|
if (IS_ERR(tmp))
|
|
return PTR_ERR(tmp);
|
|
blkdev_put(tmp, mode);
|
|
return 0;
|
|
}
|
|
|
|
static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
|
|
unsigned long arg, unsigned long flags)
|
|
{
|
|
uint64_t range[2];
|
|
uint64_t start, len;
|
|
struct request_queue *q = bdev_get_queue(bdev);
|
|
int err;
|
|
|
|
if (!(mode & FMODE_WRITE))
|
|
return -EBADF;
|
|
|
|
if (!blk_queue_discard(q))
|
|
return -EOPNOTSUPP;
|
|
|
|
if (copy_from_user(range, (void __user *)arg, sizeof(range)))
|
|
return -EFAULT;
|
|
|
|
start = range[0];
|
|
len = range[1];
|
|
|
|
if (start & 511)
|
|
return -EINVAL;
|
|
if (len & 511)
|
|
return -EINVAL;
|
|
|
|
if (start + len > i_size_read(bdev->bd_inode))
|
|
return -EINVAL;
|
|
|
|
err = truncate_bdev_range(bdev, mode, start, start + len - 1);
|
|
if (err)
|
|
return err;
|
|
|
|
return blkdev_issue_discard(bdev, start >> 9, len >> 9,
|
|
GFP_KERNEL, flags);
|
|
}
|
|
|
|
static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode,
|
|
unsigned long arg)
|
|
{
|
|
uint64_t range[2];
|
|
uint64_t start, end, len;
|
|
int err;
|
|
|
|
if (!(mode & FMODE_WRITE))
|
|
return -EBADF;
|
|
|
|
if (copy_from_user(range, (void __user *)arg, sizeof(range)))
|
|
return -EFAULT;
|
|
|
|
start = range[0];
|
|
len = range[1];
|
|
end = start + len - 1;
|
|
|
|
if (start & 511)
|
|
return -EINVAL;
|
|
if (len & 511)
|
|
return -EINVAL;
|
|
if (end >= (uint64_t)i_size_read(bdev->bd_inode))
|
|
return -EINVAL;
|
|
if (end < start)
|
|
return -EINVAL;
|
|
|
|
/* Invalidate the page cache, including dirty pages */
|
|
err = truncate_bdev_range(bdev, mode, start, end);
|
|
if (err)
|
|
return err;
|
|
|
|
return blkdev_issue_zeroout(bdev, start >> 9, len >> 9, GFP_KERNEL,
|
|
BLKDEV_ZERO_NOUNMAP);
|
|
}
|
|
|
|
static int put_ushort(unsigned short __user *argp, unsigned short val)
|
|
{
|
|
return put_user(val, argp);
|
|
}
|
|
|
|
static int put_int(int __user *argp, int val)
|
|
{
|
|
return put_user(val, argp);
|
|
}
|
|
|
|
static int put_uint(unsigned int __user *argp, unsigned int val)
|
|
{
|
|
return put_user(val, argp);
|
|
}
|
|
|
|
static int put_long(long __user *argp, long val)
|
|
{
|
|
return put_user(val, argp);
|
|
}
|
|
|
|
static int put_ulong(unsigned long __user *argp, unsigned long val)
|
|
{
|
|
return put_user(val, argp);
|
|
}
|
|
|
|
static int put_u64(u64 __user *argp, u64 val)
|
|
{
|
|
return put_user(val, argp);
|
|
}
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
static int compat_put_long(compat_long_t __user *argp, long val)
|
|
{
|
|
return put_user(val, argp);
|
|
}
|
|
|
|
static int compat_put_ulong(compat_ulong_t __user *argp, compat_ulong_t val)
|
|
{
|
|
return put_user(val, argp);
|
|
}
|
|
#endif
|
|
|
|
int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode,
|
|
unsigned cmd, unsigned long arg)
|
|
{
|
|
struct gendisk *disk = bdev->bd_disk;
|
|
|
|
if (disk->fops->ioctl)
|
|
return disk->fops->ioctl(bdev, mode, cmd, arg);
|
|
|
|
return -ENOTTY;
|
|
}
|
|
/*
|
|
* For the record: _GPL here is only because somebody decided to slap it
|
|
* on the previous export. Sheer idiocy, since it wasn't copyrightable
|
|
* at all and could be open-coded without any exports by anybody who cares.
|
|
*/
|
|
EXPORT_SYMBOL_GPL(__blkdev_driver_ioctl);
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
/*
|
|
* This is the equivalent of compat_ptr_ioctl(), to be used by block
|
|
* drivers that implement only commands that are completely compatible
|
|
* between 32-bit and 64-bit user space
|
|
*/
|
|
int blkdev_compat_ptr_ioctl(struct block_device *bdev, fmode_t mode,
|
|
unsigned cmd, unsigned long arg)
|
|
{
|
|
struct gendisk *disk = bdev->bd_disk;
|
|
|
|
if (disk->fops->ioctl)
|
|
return disk->fops->ioctl(bdev, mode, cmd,
|
|
(unsigned long)compat_ptr(arg));
|
|
|
|
return -ENOIOCTLCMD;
|
|
}
|
|
EXPORT_SYMBOL(blkdev_compat_ptr_ioctl);
|
|
#endif
|
|
|
|
static int blkdev_pr_register(struct block_device *bdev,
|
|
struct pr_registration __user *arg)
|
|
{
|
|
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
|
struct pr_registration reg;
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
if (!ops || !ops->pr_register)
|
|
return -EOPNOTSUPP;
|
|
if (copy_from_user(®, arg, sizeof(reg)))
|
|
return -EFAULT;
|
|
|
|
if (reg.flags & ~PR_FL_IGNORE_KEY)
|
|
return -EOPNOTSUPP;
|
|
return ops->pr_register(bdev, reg.old_key, reg.new_key, reg.flags);
|
|
}
|
|
|
|
static int blkdev_pr_reserve(struct block_device *bdev,
|
|
struct pr_reservation __user *arg)
|
|
{
|
|
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
|
struct pr_reservation rsv;
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
if (!ops || !ops->pr_reserve)
|
|
return -EOPNOTSUPP;
|
|
if (copy_from_user(&rsv, arg, sizeof(rsv)))
|
|
return -EFAULT;
|
|
|
|
if (rsv.flags & ~PR_FL_IGNORE_KEY)
|
|
return -EOPNOTSUPP;
|
|
return ops->pr_reserve(bdev, rsv.key, rsv.type, rsv.flags);
|
|
}
|
|
|
|
static int blkdev_pr_release(struct block_device *bdev,
|
|
struct pr_reservation __user *arg)
|
|
{
|
|
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
|
struct pr_reservation rsv;
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
if (!ops || !ops->pr_release)
|
|
return -EOPNOTSUPP;
|
|
if (copy_from_user(&rsv, arg, sizeof(rsv)))
|
|
return -EFAULT;
|
|
|
|
if (rsv.flags)
|
|
return -EOPNOTSUPP;
|
|
return ops->pr_release(bdev, rsv.key, rsv.type);
|
|
}
|
|
|
|
static int blkdev_pr_preempt(struct block_device *bdev,
|
|
struct pr_preempt __user *arg, bool abort)
|
|
{
|
|
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
|
struct pr_preempt p;
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
if (!ops || !ops->pr_preempt)
|
|
return -EOPNOTSUPP;
|
|
if (copy_from_user(&p, arg, sizeof(p)))
|
|
return -EFAULT;
|
|
|
|
if (p.flags)
|
|
return -EOPNOTSUPP;
|
|
return ops->pr_preempt(bdev, p.old_key, p.new_key, p.type, abort);
|
|
}
|
|
|
|
static int blkdev_pr_clear(struct block_device *bdev,
|
|
struct pr_clear __user *arg)
|
|
{
|
|
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
|
struct pr_clear c;
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
if (!ops || !ops->pr_clear)
|
|
return -EOPNOTSUPP;
|
|
if (copy_from_user(&c, arg, sizeof(c)))
|
|
return -EFAULT;
|
|
|
|
if (c.flags)
|
|
return -EOPNOTSUPP;
|
|
return ops->pr_clear(bdev, c.key);
|
|
}
|
|
|
|
/*
|
|
* Is it an unrecognized ioctl? The correct returns are either
|
|
* ENOTTY (final) or ENOIOCTLCMD ("I don't know this one, try a
|
|
* fallback"). ENOIOCTLCMD gets turned into ENOTTY by the ioctl
|
|
* code before returning.
|
|
*
|
|
* Confused drivers sometimes return EINVAL, which is wrong. It
|
|
* means "I understood the ioctl command, but the parameters to
|
|
* it were wrong".
|
|
*
|
|
* We should aim to just fix the broken drivers, the EINVAL case
|
|
* should go away.
|
|
*/
|
|
static inline int is_unrecognized_ioctl(int ret)
|
|
{
|
|
return ret == -EINVAL ||
|
|
ret == -ENOTTY ||
|
|
ret == -ENOIOCTLCMD;
|
|
}
|
|
|
|
static int blkdev_flushbuf(struct block_device *bdev, fmode_t mode,
|
|
unsigned cmd, unsigned long arg)
|
|
{
|
|
int ret;
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EACCES;
|
|
|
|
ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg);
|
|
if (!is_unrecognized_ioctl(ret))
|
|
return ret;
|
|
|
|
fsync_bdev(bdev);
|
|
invalidate_bdev(bdev);
|
|
return 0;
|
|
}
|
|
|
|
static int blkdev_roset(struct block_device *bdev, fmode_t mode,
|
|
unsigned cmd, unsigned long arg)
|
|
{
|
|
int ret, n;
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EACCES;
|
|
|
|
ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg);
|
|
if (!is_unrecognized_ioctl(ret))
|
|
return ret;
|
|
if (get_user(n, (int __user *)arg))
|
|
return -EFAULT;
|
|
set_device_ro(bdev, n);
|
|
return 0;
|
|
}
|
|
|
|
static int blkdev_getgeo(struct block_device *bdev,
|
|
struct hd_geometry __user *argp)
|
|
{
|
|
struct gendisk *disk = bdev->bd_disk;
|
|
struct hd_geometry geo;
|
|
int ret;
|
|
|
|
if (!argp)
|
|
return -EINVAL;
|
|
if (!disk->fops->getgeo)
|
|
return -ENOTTY;
|
|
|
|
/*
|
|
* We need to set the startsect first, the driver may
|
|
* want to override it.
|
|
*/
|
|
memset(&geo, 0, sizeof(geo));
|
|
geo.start = get_start_sect(bdev);
|
|
ret = disk->fops->getgeo(bdev, &geo);
|
|
if (ret)
|
|
return ret;
|
|
if (copy_to_user(argp, &geo, sizeof(geo)))
|
|
return -EFAULT;
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
struct compat_hd_geometry {
|
|
unsigned char heads;
|
|
unsigned char sectors;
|
|
unsigned short cylinders;
|
|
u32 start;
|
|
};
|
|
|
|
static int compat_hdio_getgeo(struct block_device *bdev,
|
|
struct compat_hd_geometry __user *ugeo)
|
|
{
|
|
struct gendisk *disk = bdev->bd_disk;
|
|
struct hd_geometry geo;
|
|
int ret;
|
|
|
|
if (!ugeo)
|
|
return -EINVAL;
|
|
if (!disk->fops->getgeo)
|
|
return -ENOTTY;
|
|
|
|
memset(&geo, 0, sizeof(geo));
|
|
/*
|
|
* We need to set the startsect first, the driver may
|
|
* want to override it.
|
|
*/
|
|
geo.start = get_start_sect(bdev);
|
|
ret = disk->fops->getgeo(bdev, &geo);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = copy_to_user(ugeo, &geo, 4);
|
|
ret |= put_user(geo.start, &ugeo->start);
|
|
if (ret)
|
|
ret = -EFAULT;
|
|
|
|
return ret;
|
|
}
|
|
#endif
|
|
|
|
/* set the logical block size */
|
|
static int blkdev_bszset(struct block_device *bdev, fmode_t mode,
|
|
int __user *argp)
|
|
{
|
|
int ret, n;
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EACCES;
|
|
if (!argp)
|
|
return -EINVAL;
|
|
if (get_user(n, argp))
|
|
return -EFAULT;
|
|
|
|
if (mode & FMODE_EXCL)
|
|
return set_blocksize(bdev, n);
|
|
|
|
if (IS_ERR(blkdev_get_by_dev(bdev->bd_dev, mode | FMODE_EXCL, &bdev)))
|
|
return -EBUSY;
|
|
ret = set_blocksize(bdev, n);
|
|
blkdev_put(bdev, mode | FMODE_EXCL);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Common commands that are handled the same way on native and compat
|
|
* user space. Note the separate arg/argp parameters that are needed
|
|
* to deal with the compat_ptr() conversion.
|
|
*/
|
|
static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode,
|
|
unsigned cmd, unsigned long arg, void __user *argp)
|
|
{
|
|
unsigned int max_sectors;
|
|
|
|
switch (cmd) {
|
|
case BLKFLSBUF:
|
|
return blkdev_flushbuf(bdev, mode, cmd, arg);
|
|
case BLKROSET:
|
|
return blkdev_roset(bdev, mode, cmd, arg);
|
|
case BLKDISCARD:
|
|
return blk_ioctl_discard(bdev, mode, arg, 0);
|
|
case BLKSECDISCARD:
|
|
return blk_ioctl_discard(bdev, mode, arg,
|
|
BLKDEV_DISCARD_SECURE);
|
|
case BLKZEROOUT:
|
|
return blk_ioctl_zeroout(bdev, mode, arg);
|
|
case BLKREPORTZONE:
|
|
return blkdev_report_zones_ioctl(bdev, mode, cmd, arg);
|
|
case BLKRESETZONE:
|
|
case BLKOPENZONE:
|
|
case BLKCLOSEZONE:
|
|
case BLKFINISHZONE:
|
|
return blkdev_zone_mgmt_ioctl(bdev, mode, cmd, arg);
|
|
case BLKGETZONESZ:
|
|
return put_uint(argp, bdev_zone_sectors(bdev));
|
|
case BLKGETNRZONES:
|
|
return put_uint(argp, blkdev_nr_zones(bdev->bd_disk));
|
|
case BLKROGET:
|
|
return put_int(argp, bdev_read_only(bdev) != 0);
|
|
case BLKSSZGET: /* get block device logical block size */
|
|
return put_int(argp, bdev_logical_block_size(bdev));
|
|
case BLKPBSZGET: /* get block device physical block size */
|
|
return put_uint(argp, bdev_physical_block_size(bdev));
|
|
case BLKIOMIN:
|
|
return put_uint(argp, bdev_io_min(bdev));
|
|
case BLKIOOPT:
|
|
return put_uint(argp, bdev_io_opt(bdev));
|
|
case BLKALIGNOFF:
|
|
return put_int(argp, bdev_alignment_offset(bdev));
|
|
case BLKDISCARDZEROES:
|
|
return put_uint(argp, 0);
|
|
case BLKSECTGET:
|
|
max_sectors = min_t(unsigned int, USHRT_MAX,
|
|
queue_max_sectors(bdev_get_queue(bdev)));
|
|
return put_ushort(argp, max_sectors);
|
|
case BLKROTATIONAL:
|
|
return put_ushort(argp, !blk_queue_nonrot(bdev_get_queue(bdev)));
|
|
case BLKRASET:
|
|
case BLKFRASET:
|
|
if(!capable(CAP_SYS_ADMIN))
|
|
return -EACCES;
|
|
bdev->bd_bdi->ra_pages = (arg * 512) / PAGE_SIZE;
|
|
return 0;
|
|
case BLKRRPART:
|
|
return blkdev_reread_part(bdev, mode);
|
|
case BLKTRACESTART:
|
|
case BLKTRACESTOP:
|
|
case BLKTRACETEARDOWN:
|
|
return blk_trace_ioctl(bdev, cmd, argp);
|
|
case IOC_PR_REGISTER:
|
|
return blkdev_pr_register(bdev, argp);
|
|
case IOC_PR_RESERVE:
|
|
return blkdev_pr_reserve(bdev, argp);
|
|
case IOC_PR_RELEASE:
|
|
return blkdev_pr_release(bdev, argp);
|
|
case IOC_PR_PREEMPT:
|
|
return blkdev_pr_preempt(bdev, argp, false);
|
|
case IOC_PR_PREEMPT_ABORT:
|
|
return blkdev_pr_preempt(bdev, argp, true);
|
|
case IOC_PR_CLEAR:
|
|
return blkdev_pr_clear(bdev, argp);
|
|
default:
|
|
return -ENOIOCTLCMD;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Always keep this in sync with compat_blkdev_ioctl()
|
|
* to handle all incompatible commands in both functions.
|
|
*
|
|
* New commands must be compatible and go into blkdev_common_ioctl
|
|
*/
|
|
int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
|
|
unsigned long arg)
|
|
{
|
|
int ret;
|
|
loff_t size;
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
switch (cmd) {
|
|
/* These need separate implementations for the data structure */
|
|
case HDIO_GETGEO:
|
|
return blkdev_getgeo(bdev, argp);
|
|
case BLKPG:
|
|
return blkpg_ioctl(bdev, argp);
|
|
|
|
/* Compat mode returns 32-bit data instead of 'long' */
|
|
case BLKRAGET:
|
|
case BLKFRAGET:
|
|
if (!argp)
|
|
return -EINVAL;
|
|
return put_long(argp, (bdev->bd_bdi->ra_pages*PAGE_SIZE) / 512);
|
|
case BLKGETSIZE:
|
|
size = i_size_read(bdev->bd_inode);
|
|
if ((size >> 9) > ~0UL)
|
|
return -EFBIG;
|
|
return put_ulong(argp, size >> 9);
|
|
|
|
/* The data is compatible, but the command number is different */
|
|
case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */
|
|
return put_int(argp, block_size(bdev));
|
|
case BLKBSZSET:
|
|
return blkdev_bszset(bdev, mode, argp);
|
|
case BLKGETSIZE64:
|
|
return put_u64(argp, i_size_read(bdev->bd_inode));
|
|
|
|
/* Incompatible alignment on i386 */
|
|
case BLKTRACESETUP:
|
|
return blk_trace_ioctl(bdev, cmd, argp);
|
|
default:
|
|
break;
|
|
}
|
|
|
|
ret = blkdev_common_ioctl(bdev, mode, cmd, arg, argp);
|
|
if (ret == -ENOIOCTLCMD)
|
|
return __blkdev_driver_ioctl(bdev, mode, cmd, arg);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(blkdev_ioctl); /* for /dev/raw */
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
#define BLKBSZGET_32 _IOR(0x12, 112, int)
|
|
#define BLKBSZSET_32 _IOW(0x12, 113, int)
|
|
#define BLKGETSIZE64_32 _IOR(0x12, 114, int)
|
|
|
|
/* Most of the generic ioctls are handled in the normal fallback path.
|
|
This assumes the blkdev's low level compat_ioctl always returns
|
|
ENOIOCTLCMD for unknown ioctls. */
|
|
long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
|
|
{
|
|
int ret;
|
|
void __user *argp = compat_ptr(arg);
|
|
struct inode *inode = file->f_mapping->host;
|
|
struct block_device *bdev = inode->i_bdev;
|
|
struct gendisk *disk = bdev->bd_disk;
|
|
fmode_t mode = file->f_mode;
|
|
loff_t size;
|
|
|
|
/*
|
|
* O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have
|
|
* to updated it before every ioctl.
|
|
*/
|
|
if (file->f_flags & O_NDELAY)
|
|
mode |= FMODE_NDELAY;
|
|
else
|
|
mode &= ~FMODE_NDELAY;
|
|
|
|
switch (cmd) {
|
|
/* These need separate implementations for the data structure */
|
|
case HDIO_GETGEO:
|
|
return compat_hdio_getgeo(bdev, argp);
|
|
case BLKPG:
|
|
return compat_blkpg_ioctl(bdev, argp);
|
|
|
|
/* Compat mode returns 32-bit data instead of 'long' */
|
|
case BLKRAGET:
|
|
case BLKFRAGET:
|
|
if (!argp)
|
|
return -EINVAL;
|
|
return compat_put_long(argp,
|
|
(bdev->bd_bdi->ra_pages * PAGE_SIZE) / 512);
|
|
case BLKGETSIZE:
|
|
size = i_size_read(bdev->bd_inode);
|
|
if ((size >> 9) > ~(compat_ulong_t)0)
|
|
return -EFBIG;
|
|
return compat_put_ulong(argp, size >> 9);
|
|
|
|
/* The data is compatible, but the command number is different */
|
|
case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */
|
|
return put_int(argp, bdev_logical_block_size(bdev));
|
|
case BLKBSZSET_32:
|
|
return blkdev_bszset(bdev, mode, argp);
|
|
case BLKGETSIZE64_32:
|
|
return put_u64(argp, i_size_read(bdev->bd_inode));
|
|
|
|
/* Incompatible alignment on i386 */
|
|
case BLKTRACESETUP32:
|
|
return blk_trace_ioctl(bdev, cmd, argp);
|
|
default:
|
|
break;
|
|
}
|
|
|
|
ret = blkdev_common_ioctl(bdev, mode, cmd, arg, argp);
|
|
if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl)
|
|
ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg);
|
|
|
|
return ret;
|
|
}
|
|
#endif
|