NFSv4: nfs4_proc_set_acl needs to restore NFS_CAP_UIDGID_NOMAP on error.
Subsystems (6)
Sasha Levin
maintainerPATCH 5/8 radeon: use memcpy_to/fromio for UVD fw upload
In reply to Sasha LevinFrom: Chen Li <[email protected]>
[ Upstream commit ab8363d3875a83f4901eb1cc00ce8afd24de6c85 ]
I met a gpu addr bug recently and the kernel log tells me the pc is memcpy/memset and link register is radeon_uvd_resume.
As we know, in some architectures, optimized memcpy/memset may not work well on device memory. Trival memcpy_toio/memset_io can fix this problem.
BTW, amdgpu has already done it in:
commit ba0b2275a678 ("drm/amdgpu: use memcpy_to/fromio for UVD fw upload"), that's why it has no this issue on the same gpu and platform.
--- drivers/gpu/drm/radeon/radeon_uvd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_uvd.c +2 -2
@@ -286,7 +286,7 @@ int radeon_uvd_resume(struct radeon_device *rdev)if (rdev->uvd.vcpu_bo ==NULL )return -EINVAL ; -memcpy (rdev->uvd.cpu_addr, rdev->uvd_fw->data, rdev->uvd_fw->size); +memcpy_toio ((void __iomem *)rdev->uvd.cpu_addr, rdev->uvd_fw->data, rdev->uvd_fw->size); size =radeon_bo_size (rdev->uvd.vcpu_bo); size -= rdev->uvd_fw->size;
@@ -294,7 +294,7 @@ int radeon_uvd_resume(struct radeon_device *rdev) ptr = rdev->uvd.cpu_addr; ptr += rdev->uvd_fw->size; -memset (ptr,0 , size); +memset_io ((void __iomem *)ptr,0 , size);return 0 ; }
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 1/8 NFSv4: nfs4_proc_set_acl needs to restore NFS_CAP_UIDGID_NOMAP on error.
From: Dai Ngo <[email protected]>
[ Upstream commit f8849e206ef52b584cd9227255f4724f0cc900bb ]
Currently if __nfs4_proc_set_acl fails with NFS4ERR_BADOWNER it re-enables the idmapper by clearing NFS_CAP_UIDGID_NOMAP before retrying again. The NFS_CAP_UIDGID_NOMAP remains cleared even if the retry fails. This causes problem for subsequent setattr requests for v4 server that does not have idmapping configured.
This patch modifies nfs4_proc_set_acl to detect NFS4ERR_BADOWNER and NFS4ERR_BADNAME and skips the retry, since the kernel isn't involved in encoding the ACEs, and return -EINVAL.
Steps to reproduce the problem:
# mount -o vers=4.1,sec=sys server:/export/test /tmp/mnt # touch /tmp/mnt/file1 # chown 99 /tmp/mnt/file1 # nfs4_setfacl -a A::[email protected]:wrtncy /tmp/mnt/file1 Failed setxattr operation: Invalid argument # chown 99 /tmp/mnt/file1 chown: changing ownership of ‘/tmp/mnt/file1’: Invalid argument # umount /tmp/mnt # mount -o vers=4.1,sec=sys server:/export/test /tmp/mnt # chown 99 /tmp/mnt/file1 #
v2: detect NFS4ERR_BADOWNER and NFS4ERR_BADNAME and skip retry
in nfs4_proc_set_acl.
--- fs/nfs/nfs4proc.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/nfs/nfs4proc.c +8 -0
@@ -5294,6 +5294,14 @@ static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflendo { err =__nfs4_proc_set_acl (inode, buf, buflen);trace_nfs4_set_acl (inode, err); +if (err == -NFS4ERR_BADOWNER || err == -NFS4ERR_BADNAME ) { +/* +* no need to retry since the kernel +* isn't involved in encoding the ACEs. +*/ + err = -EINVAL ; +break ; + } err =nfs4_handle_exception (NFS_SERVER (inode), err, &exception); }while (exception.retry);
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 2/8 scsi: core: Fix error handling of scsi_host_alloc()
From: Ming Lei <[email protected]>
[ Upstream commit 66a834d092930cf41d809c0e989b13cd6f9ca006 ]
After device is initialized via device_initialize(), or its name is set via dev_set_name(), the device has to be freed via put_device(). Otherwise device name will be leaked because it is allocated dynamically in dev_set_name().
Fix the leak by replacing kfree() with put_device(). Since scsi_host_dev_release() properly handles IDA and kthread removal, remove special-casing these from the error handling as well.
--- drivers/scsi/hosts.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
drivers/scsi/hosts.c +13 -10
@@ -404,8 +404,10 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)mutex_init (&shost->scan_mutex); index =ida_simple_get (&host_index_ida,0 ,0 ,GFP_KERNEL ); -if (index <0 ) - goto fail_kfree; +if (index <0 ) { +kfree (shost); +return NULL ; + } shost->host_no = index; shost->dma_channel =0xff ;
@@ -493,7 +495,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)shost_printk (KERN_WARNING , shost,"error handler thread failed to spawn, error = %ld\n" ,PTR_ERR (shost->ehandler)); - goto fail_index_remove; + goto fail; } shost->tmf_work_q = alloc_workqueue("scsi_tmf_%d",
@@ -502,17 +504,18 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)if (!shost->tmf_work_q) {shost_printk (KERN_WARNING , shost,"failed to create tmf workq\n" ); - goto fail_kthread; + goto fail; }scsi_proc_hostdir_add (shost->hostt);return shost; + fail: +/* +* Host state is still SHOST_CREATED and that is enough to release +* ->shost_gendev. scsi_host_dev_release() will free +* dev_name(&shost->shost_dev). +*/ +put_device (&shost->shost_gendev); - fail_kthread: -kthread_stop (shost->ehandler); - fail_index_remove: -ida_simple_remove (&host_index_ida, shost->host_no); - fail_kfree: -kfree (shost);return NULL ; }EXPORT_SYMBOL (scsi_host_alloc);
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 3/8 scsi: core: Put .shost_dev in failure path if host state changes to RUNNING
In reply to Sasha LevinFrom: Ming Lei <[email protected]>
[ Upstream commit 11714026c02d613c30a149c3f4c4a15047744529 ]
scsi_host_dev_release() only frees dev_name when host state is SHOST_CREATED. After host state has changed to SHOST_RUNNING, scsi_host_dev_release() no longer cleans up.
Fix this by doing a put_device(&shost->shost_dev) in the failure path when host state is SHOST_RUNNING. Move get_device(&shost->shost_gendev) before device_add(&shost->shost_dev) so that scsi_host_cls_release() can do a put on this reference.
--- drivers/scsi/hosts.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/scsi/hosts.c +6 -2
@@ -256,12 +256,11 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,device_enable_async_suspend (&shost->shost_dev); +get_device (&shost->shost_gendev); error =device_add (&shost->shost_dev);if (error) goto out_del_gendev; -get_device (&shost->shost_gendev); -if (shost->transportt->host_size) { shost->shost_data =kzalloc (shost->transportt->host_size,GFP_KERNEL );
@@ -298,6 +297,11 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, out_del_dev:device_del (&shost->shost_dev); out_del_gendev: +/* +* Host state is SHOST_RUNNING so we have to explicitly release +* ->shost_dev. +*/ +put_device (&shost->shost_dev);device_del (&shost->shost_gendev); out_disable_runtime_pm:device_disable_async_suspend (&shost->shost_gendev);
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 4/8 scsi: core: Only put parent device if host state differs from SHOST_CREATED
In reply to Sasha LevinFrom: Ming Lei <[email protected]>
[ Upstream commit 1e0d4e6225996f05271de1ebcb1a7c9381af0b27 ]
get_device(shost->shost_gendev.parent) is called after host state has switched to SHOST_RUNNING. scsi_host_dev_release() shouldn't release the parent device if host state is still SHOST_CREATED.
--- drivers/scsi/hosts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/hosts.c +1 -1
@@ -355,7 +355,7 @@ static void scsi_host_dev_release(struct device *dev)ida_simple_remove (&host_index_ida, shost->host_no); -if (parent) +if (shost->shost_state !=SHOST_CREATED )put_device (parent);kfree (shost); }
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 6/8 kvm: avoid speculation-based attacks from out-of-range memslot accesses
In reply to Sasha LevinFrom: Paolo Bonzini <[email protected]>
[ Upstream commit da27a83fd6cc7780fea190e1f5c19e87019da65c ]
KVM's mechanism for accessing guest memory translates a guest physical address (gpa) to a host virtual address using the right-shifted gpa (also known as gfn) and a struct kvm_memory_slot. The translation is performed in __gfn_to_hva_memslot using the following formula:
hva = slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE
It is expected that gfn falls within the boundaries of the guest's physical memory. However, a guest can access invalid physical addresses in such a way that the gfn is invalid.
__gfn_to_hva_memslot is called from kvm_vcpu_gfn_to_hva_prot, which first retrieves a memslot through __gfn_to_memslot. While __gfn_to_memslot does check that the gfn falls within the boundaries of the guest's physical memory or not, a CPU can speculate the result of the check and continue execution speculatively using an illegal gfn. The speculation can result in calculating an out-of-bounds hva. If the resulting host virtual address is used to load another guest physical address, this is effectively a Spectre gadget consisting of two consecutive reads, the second of which is data dependent on the first.
Right now it's not clear if there are any cases in which this is exploitable. One interesting case was reported by the original author of this patch, and involves visiting guest page tables on x86. Right now these are not vulnerable because the hva read goes through get_user(), which contains an LFENCE speculation barrier. However, there are patches in progress for x86 uaccess.h to mask kernel addresses instead of using LFENCE; once these land, a guest could use speculation to read from the VMM's ring 3 address space. Other architectures such as ARM already use the address masking method, and would be susceptible to this same kind of data-dependent access gadgets. Therefore, this patch proactively protects from these attacks by masking out-of-bounds gfns in __gfn_to_hva_memslot, which blocks speculation of invalid hvas.
Sean Christopherson noted that this patch does not cover kvm_read_guest_offset_cached. This however is limited to a few bytes past the end of the cache, and therefore it is unlikely to be useful in the context of building a chain of data dependent accesses.
--- include/linux/kvm_host.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
include/linux/kvm_host.h +9 -1
@@ -963,7 +963,15 @@ __gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn)static inline unsigned long __gfn_to_hva_memslot (struct kvm_memory_slot *slot,gfn_t gfn) { -return slot->userspace_addr + (gfn - slot->base_gfn) *PAGE_SIZE ; +/* +* The index was checked originally in search_memslots. To avoid +* that a malicious guest builds a Spectre gadget out of e.g. page +* table walks, do not let the processor speculate loads outside +* the guest's registered memslots. +*/ +unsigned long offset =array_index_nospec (gfn - slot->base_gfn, + slot->npages); +return slot->userspace_addr + offset *PAGE_SIZE ; }static inline int memslot_id (struct kvm *kvm,gfn_t gfn)
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 7/8 kvm: fix previous commit for 32-bit builds
In reply to Sasha LevinFrom: Paolo Bonzini <[email protected]>
[ Upstream commit 4422829e8053068e0225e4d0ef42dc41ea7c9ef5 ]
array_index_nospec does not work for uint64_t on 32-bit builds. However, the size of a memory slot must be less than 20 bits wide on those system, since the memory slot must fit in the user address space. So just store it in an unsigned long.
--- include/linux/kvm_host.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/kvm_host.h +2 -2
@@ -969,8 +969,8 @@ __gfn_to_hva_memslot(struct kvm_memory_slot *slot, gfn_t gfn)* table walks, do not let the processor speculate loads outside * the guest's registered memslots. */ -unsigned long offset =array_index_nospec (gfn - slot->base_gfn, - slot->npages); +unsigned long offset = gfn - slot->base_gfn; + offset =array_index_nospec (offset, slot->npages);return slot->userspace_addr + offset *PAGE_SIZE ; }
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 8/8 hwmon: (scpi-hwmon) shows the negative temperature properly
In reply to Sasha LevinFrom: Riwen Lu <[email protected]>
[ Upstream commit 78d13552346289bad4a9bf8eabb5eec5e5a321a5 ]
The scpi hwmon shows the sub-zero temperature in an unsigned integer, which would confuse the users when the machine works in low temperature environment. This shows the sub-zero temperature in an signed value and users can get it properly from sensors.
--- drivers/hwmon/scpi-hwmon.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/hwmon/scpi-hwmon.c +9 -0
@@ -107,6 +107,15 @@ scpi_show_sensor(struct device *dev, struct device_attribute *attr, char *buf)scpi_scale_reading (&value, sensor); +/* +* Temperature sensor values are treated as signed values based on +* observation even though that is not explicitly specified, and +* because an unsigned u64 temperature does not really make practical +* sense especially when the temperature is below zero degrees Celsius. +*/ +if (sensor->info.class ==TEMPERATURE ) +return sprintf (buf,"%lld\n" , (s64 )value); +return sprintf (buf,"%llu\n" , value); }
Signature · 1 line
2.30.2