android_kernel_xiaomi_sm8350/fs/afs/xattr.c
Greg Kroah-Hartman 4ed2c4aeee This is the 5.4.108 stable release
-----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmBbFBwACgkQONu9yGCS
 aT7OPRAAjM8308gp5zU5h7gV20AlMLEfav5BhSJB1NGac8RKJT/kr7CoYt2JWZgO
 jW4f1uxcjVJypuijkvMPu6+fdDDCen91691F9YqA5B+BdxSC+Vc4MCdhRKWffTtU
 /vJPrspOWMW7sXGTIXuUyD7zXoUECdmRFb0N62ZOgCiv99aEhxAUsHWF1RIiWfhM
 p06/WnEkgSpo2hmE369QAnsp8qox6NeTci/7tHbW5/JmjLGCVUf99l2UC7mLZU5a
 sRQ9Mpb7v78umqmqDct75pKnl3nOfmejIvvPdsQFvs+mgNfPElG/C8WW7JhquA2+
 mpnZeVeHyI3MM5/wCSARsYu5m8KnbzOoZ/Ku8B+cblEekZ/yaJx5cSCEMTGi5Ekh
 noK1IRO0R7UqnV4I36eOY5YNWu6kgHm4/7Zj0Ous5sC6RDjbgNpTgFONvxPzDoo2
 5OAX5hf604XXS5dhpQR5RYiU/KH7Ms+nWYViKRCeIuQp8qvyq1pb5X+tPXisetQC
 1mylvqiDqeUqdgdwtx8ShN8PH2uyu+dVzWgD+b/DVHM+Rmll+en0LvckmEagH5SV
 mpBW8j5yPJmdFeIufkibxx6Sr9mT/kbH8QQa/W1ojkya/+Ky1wbCdqVR+BFh/sc0
 60Zyoyns3r5o3IM7UrQ9Glb1aYZYJtx/3W2tPKtaczSzj4beVGw=
 =OoCo
 -----END PGP SIGNATURE-----

Merge 5.4.108 into android11-5.4-lts

Changes in 5.4.108
	ASoC: ak4458: Add MODULE_DEVICE_TABLE
	ASoC: ak5558: Add MODULE_DEVICE_TABLE
	ALSA: dice: fix null pointer dereference when node is disconnected
	ALSA: hda/realtek: apply pin quirk for XiaomiNotebook Pro
	ALSA: hda: generic: Fix the micmute led init state
	ALSA: hda/realtek: Apply headset-mic quirks for Xiaomi Redmibook Air
	Revert "PM: runtime: Update device status before letting suppliers suspend"
	s390/vtime: fix increased steal time accounting
	ARM: 9030/1: entry: omit FP emulation for UND exceptions taken in kernel mode
	ARM: 9044/1: vfp: use undef hook for VFP support detection
	btrfs: fix race when cloning extent buffer during rewind of an old root
	btrfs: fix slab cache flags for free space tree bitmap
	ASoC: fsl_ssi: Fix TDM slot setup for I2S mode
	ASoC: SOF: Intel: unregister DMIC device on probe error
	ASoC: SOF: intel: fix wrong poll bits in dsp power down
	ASoC: simple-card-utils: Do not handle device clock
	afs: Stop listxattr() from listing "afs.*" attributes
	nvme: fix Write Zeroes limitations
	nvme-tcp: fix possible hang when failing to set io queues
	nvme-tcp: fix a NULL deref when receiving a 0-length r2t PDU
	nvmet: don't check iosqes,iocqes for discovery controllers
	nfsd: Don't keep looking up unhashed files in the nfsd file cache
	NFSD: Repair misuse of sv_lock in 5.10.16-rt30.
	svcrdma: disable timeouts on rdma backchannel
	vfio: IOMMU_API should be selected
	sunrpc: fix refcount leak for rpc auth modules
	net/qrtr: fix __netdev_alloc_skb call
	kbuild: Fix <linux/version.h> for empty SUBLEVEL or PATCHLEVEL again
	riscv: Correct SPARSEMEM configuration
	scsi: lpfc: Fix some error codes in debugfs
	scsi: myrs: Fix a double free in myrs_cleanup()
	counter: stm32-timer-cnt: Report count function when SLAVE_MODE_DISABLED
	nvme-rdma: fix possible hang when failing to set io queues
	usb-storage: Add quirk to defeat Kindle's automatic unload
	usbip: Fix incorrect double assignment to udc->ud.tcp_rx
	USB: replace hardcode maximum usb string length by definition
	usb: gadget: configfs: Fix KASAN use-after-free
	usb: typec: tcpm: Invoke power_supply_changed for tcpm-source-psy-
	iio:adc:stm32-adc: Add HAS_IOMEM dependency
	iio:adc:qcom-spmi-vadc: add default scale to LR_MUX2_BAT_ID channel
	iio: adis16400: Fix an error code in adis16400_initial_setup()
	iio: gyro: mpu3050: Fix error handling in mpu3050_trigger_handler
	iio: adc: ad7949: fix wrong ADC result due to incorrect bit mask
	iio: hid-sensor-humidity: Fix alignment issue of timestamp channel
	iio: hid-sensor-prox: Fix scale not correct issue
	iio: hid-sensor-temperature: Fix issues of timestamp channel
	counter: stm32-timer-cnt: fix ceiling write max value
	PCI: rpadlpar: Fix potential drc_name corruption in store functions
	perf/x86/intel: Fix a crash caused by zero PEBS status
	x86/ioapic: Ignore IRQ2 again
	kernel, fs: Introduce and use set_restart_fn() and arch_set_restart_data()
	x86: Move TS_COMPAT back to asm/thread_info.h
	x86: Introduce TS_COMPAT_RESTART to fix get_nr_restart_syscall()
	ext4: find old entry again if failed to rename whiteout
	ext4: do not try to set xattr into ea_inode if value is empty
	ext4: fix potential error in ext4_do_update_inode
	efi: use 32-bit alignment for efi_guid_t literals
	firmware/efi: Fix a use after bug in efi_mem_reserve_persistent
	genirq: Disable interrupts for force threaded handlers
	x86/apic/of: Fix CPU devicetree-node lookups
	cifs: Fix preauth hash corruption
	Linux 5.4.108

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I9208519e886cf620d37826a0c4b6f88fcd4a090b
2021-03-24 11:52:12 +01:00

407 lines
9.2 KiB
C

// SPDX-License-Identifier: GPL-2.0-or-later
/* Extended attribute handling for AFS. We use xattrs to get and set metadata
* instead of providing pioctl().
*
* Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*/
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/xattr.h>
#include "internal.h"
/*
* Get a file's ACL.
*/
static int afs_xattr_get_acl(const struct xattr_handler *handler,
struct dentry *dentry,
struct inode *inode, const char *name,
void *buffer, size_t size, int flags)
{
struct afs_fs_cursor fc;
struct afs_status_cb *scb;
struct afs_vnode *vnode = AFS_FS_I(inode);
struct afs_acl *acl = NULL;
struct key *key;
int ret = -ENOMEM;
scb = kzalloc(sizeof(struct afs_status_cb), GFP_NOFS);
if (!scb)
goto error;
key = afs_request_key(vnode->volume->cell);
if (IS_ERR(key)) {
ret = PTR_ERR(key);
goto error_scb;
}
ret = -ERESTARTSYS;
if (afs_begin_vnode_operation(&fc, vnode, key, true)) {
afs_dataversion_t data_version = vnode->status.data_version;
while (afs_select_fileserver(&fc)) {
fc.cb_break = afs_calc_vnode_cb_break(vnode);
acl = afs_fs_fetch_acl(&fc, scb);
}
afs_check_for_remote_deletion(&fc, fc.vnode);
afs_vnode_commit_status(&fc, vnode, fc.cb_break,
&data_version, scb);
ret = afs_end_vnode_operation(&fc);
}
if (ret == 0) {
ret = acl->size;
if (size > 0) {
if (acl->size <= size)
memcpy(buffer, acl->data, acl->size);
else
ret = -ERANGE;
}
kfree(acl);
}
key_put(key);
error_scb:
kfree(scb);
error:
return ret;
}
/*
* Set a file's AFS3 ACL.
*/
static int afs_xattr_set_acl(const struct xattr_handler *handler,
struct dentry *dentry,
struct inode *inode, const char *name,
const void *buffer, size_t size, int flags)
{
struct afs_fs_cursor fc;
struct afs_status_cb *scb;
struct afs_vnode *vnode = AFS_FS_I(inode);
struct afs_acl *acl = NULL;
struct key *key;
int ret = -ENOMEM;
if (flags == XATTR_CREATE)
return -EINVAL;
scb = kzalloc(sizeof(struct afs_status_cb), GFP_NOFS);
if (!scb)
goto error;
acl = kmalloc(sizeof(*acl) + size, GFP_KERNEL);
if (!acl)
goto error_scb;
key = afs_request_key(vnode->volume->cell);
if (IS_ERR(key)) {
ret = PTR_ERR(key);
goto error_acl;
}
acl->size = size;
memcpy(acl->data, buffer, size);
ret = -ERESTARTSYS;
if (afs_begin_vnode_operation(&fc, vnode, key, true)) {
afs_dataversion_t data_version = vnode->status.data_version;
while (afs_select_fileserver(&fc)) {
fc.cb_break = afs_calc_vnode_cb_break(vnode);
afs_fs_store_acl(&fc, acl, scb);
}
afs_check_for_remote_deletion(&fc, fc.vnode);
afs_vnode_commit_status(&fc, vnode, fc.cb_break,
&data_version, scb);
ret = afs_end_vnode_operation(&fc);
}
key_put(key);
error_acl:
kfree(acl);
error_scb:
kfree(scb);
error:
return ret;
}
static const struct xattr_handler afs_xattr_afs_acl_handler = {
.name = "afs.acl",
.get = afs_xattr_get_acl,
.set = afs_xattr_set_acl,
};
/*
* Get a file's YFS ACL.
*/
static int afs_xattr_get_yfs(const struct xattr_handler *handler,
struct dentry *dentry,
struct inode *inode, const char *name,
void *buffer, size_t size, int flags)
{
struct afs_fs_cursor fc;
struct afs_status_cb *scb;
struct afs_vnode *vnode = AFS_FS_I(inode);
struct yfs_acl *yacl = NULL;
struct key *key;
char buf[16], *data;
int which = 0, dsize, ret = -ENOMEM;
if (strcmp(name, "acl") == 0)
which = 0;
else if (strcmp(name, "acl_inherited") == 0)
which = 1;
else if (strcmp(name, "acl_num_cleaned") == 0)
which = 2;
else if (strcmp(name, "vol_acl") == 0)
which = 3;
else
return -EOPNOTSUPP;
yacl = kzalloc(sizeof(struct yfs_acl), GFP_KERNEL);
if (!yacl)
goto error;
if (which == 0)
yacl->flags |= YFS_ACL_WANT_ACL;
else if (which == 3)
yacl->flags |= YFS_ACL_WANT_VOL_ACL;
scb = kzalloc(sizeof(struct afs_status_cb), GFP_NOFS);
if (!scb)
goto error_yacl;
key = afs_request_key(vnode->volume->cell);
if (IS_ERR(key)) {
ret = PTR_ERR(key);
goto error_scb;
}
ret = -ERESTARTSYS;
if (afs_begin_vnode_operation(&fc, vnode, key, true)) {
afs_dataversion_t data_version = vnode->status.data_version;
while (afs_select_fileserver(&fc)) {
fc.cb_break = afs_calc_vnode_cb_break(vnode);
yfs_fs_fetch_opaque_acl(&fc, yacl, scb);
}
afs_check_for_remote_deletion(&fc, fc.vnode);
afs_vnode_commit_status(&fc, vnode, fc.cb_break,
&data_version, scb);
ret = afs_end_vnode_operation(&fc);
}
if (ret < 0)
goto error_key;
switch (which) {
case 0:
data = yacl->acl->data;
dsize = yacl->acl->size;
break;
case 1:
data = buf;
dsize = scnprintf(buf, sizeof(buf), "%u", yacl->inherit_flag);
break;
case 2:
data = buf;
dsize = scnprintf(buf, sizeof(buf), "%u", yacl->num_cleaned);
break;
case 3:
data = yacl->vol_acl->data;
dsize = yacl->vol_acl->size;
break;
default:
ret = -EOPNOTSUPP;
goto error_key;
}
ret = dsize;
if (size > 0) {
if (dsize > size) {
ret = -ERANGE;
goto error_key;
}
memcpy(buffer, data, dsize);
}
error_key:
key_put(key);
error_scb:
kfree(scb);
error_yacl:
yfs_free_opaque_acl(yacl);
error:
return ret;
}
/*
* Set a file's YFS ACL.
*/
static int afs_xattr_set_yfs(const struct xattr_handler *handler,
struct dentry *dentry,
struct inode *inode, const char *name,
const void *buffer, size_t size, int flags)
{
struct afs_fs_cursor fc;
struct afs_status_cb *scb;
struct afs_vnode *vnode = AFS_FS_I(inode);
struct afs_acl *acl = NULL;
struct key *key;
int ret = -ENOMEM;
if (flags == XATTR_CREATE ||
strcmp(name, "acl") != 0)
return -EINVAL;
scb = kzalloc(sizeof(struct afs_status_cb), GFP_NOFS);
if (!scb)
goto error;
acl = kmalloc(sizeof(*acl) + size, GFP_KERNEL);
if (!acl)
goto error_scb;
acl->size = size;
memcpy(acl->data, buffer, size);
key = afs_request_key(vnode->volume->cell);
if (IS_ERR(key)) {
ret = PTR_ERR(key);
goto error_acl;
}
ret = -ERESTARTSYS;
if (afs_begin_vnode_operation(&fc, vnode, key, true)) {
afs_dataversion_t data_version = vnode->status.data_version;
while (afs_select_fileserver(&fc)) {
fc.cb_break = afs_calc_vnode_cb_break(vnode);
yfs_fs_store_opaque_acl2(&fc, acl, scb);
}
afs_check_for_remote_deletion(&fc, fc.vnode);
afs_vnode_commit_status(&fc, vnode, fc.cb_break,
&data_version, scb);
ret = afs_end_vnode_operation(&fc);
}
error_acl:
kfree(acl);
key_put(key);
error_scb:
kfree(scb);
error:
return ret;
}
static const struct xattr_handler afs_xattr_yfs_handler = {
.prefix = "afs.yfs.",
.get = afs_xattr_get_yfs,
.set = afs_xattr_set_yfs,
};
/*
* Get the name of the cell on which a file resides.
*/
static int afs_xattr_get_cell(const struct xattr_handler *handler,
struct dentry *dentry,
struct inode *inode, const char *name,
void *buffer, size_t size, int flags)
{
struct afs_vnode *vnode = AFS_FS_I(inode);
struct afs_cell *cell = vnode->volume->cell;
size_t namelen;
namelen = cell->name_len;
if (size == 0)
return namelen;
if (namelen > size)
return -ERANGE;
memcpy(buffer, cell->name, namelen);
return namelen;
}
static const struct xattr_handler afs_xattr_afs_cell_handler = {
.name = "afs.cell",
.get = afs_xattr_get_cell,
};
/*
* Get the volume ID, vnode ID and vnode uniquifier of a file as a sequence of
* hex numbers separated by colons.
*/
static int afs_xattr_get_fid(const struct xattr_handler *handler,
struct dentry *dentry,
struct inode *inode, const char *name,
void *buffer, size_t size, int flags)
{
struct afs_vnode *vnode = AFS_FS_I(inode);
char text[16 + 1 + 24 + 1 + 8 + 1];
size_t len;
/* The volume ID is 64-bit, the vnode ID is 96-bit and the
* uniquifier is 32-bit.
*/
len = scnprintf(text, sizeof(text), "%llx:", vnode->fid.vid);
if (vnode->fid.vnode_hi)
len += scnprintf(text + len, sizeof(text) - len, "%x%016llx",
vnode->fid.vnode_hi, vnode->fid.vnode);
else
len += scnprintf(text + len, sizeof(text) - len, "%llx",
vnode->fid.vnode);
len += scnprintf(text + len, sizeof(text) - len, ":%x",
vnode->fid.unique);
if (size == 0)
return len;
if (len > size)
return -ERANGE;
memcpy(buffer, text, len);
return len;
}
static const struct xattr_handler afs_xattr_afs_fid_handler = {
.name = "afs.fid",
.get = afs_xattr_get_fid,
};
/*
* Get the name of the volume on which a file resides.
*/
static int afs_xattr_get_volume(const struct xattr_handler *handler,
struct dentry *dentry,
struct inode *inode, const char *name,
void *buffer, size_t size, int flags)
{
struct afs_vnode *vnode = AFS_FS_I(inode);
const char *volname = vnode->volume->name;
size_t namelen;
namelen = strlen(volname);
if (size == 0)
return namelen;
if (namelen > size)
return -ERANGE;
memcpy(buffer, volname, namelen);
return namelen;
}
static const struct xattr_handler afs_xattr_afs_volume_handler = {
.name = "afs.volume",
.get = afs_xattr_get_volume,
};
const struct xattr_handler *afs_xattr_handlers[] = {
&afs_xattr_afs_acl_handler,
&afs_xattr_afs_cell_handler,
&afs_xattr_afs_fid_handler,
&afs_xattr_afs_volume_handler,
&afs_xattr_yfs_handler, /* afs.yfs. prefix */
NULL
};