6.12.97-rc1 review
Subsystems (12)
Greg Kroah-Hartman
maintainerPATCH 533/1276 PCI: mediatek: Fix possible truncation in mtk_pcie_parse_port()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryder Lee <[email protected]>
[ Upstream commit ab4a4043db1fcc4fd4c5745c5be8caf053502e29 ]
As reported by the W=1 warning below, content of the 'name' variable might get truncated with the existing size of 10 bytes. Though it is not practically possible to exceed the 10 bytes size, increase it to 20 to silence the warning for a clean W=1 build:
$ make W=1 drivers/pci/controller/pcie-mediatek.o
CALL scripts/checksyscalls.sh
DESCEND objtool
INSTALL libsubcmd_headers
CC drivers/pci/controller/pcie-mediatek.o
drivers/pci/controller/pcie-mediatek.c: In function ‘mtk_pcie_parse_port’:
drivers/pci/controller/pcie-mediatek.c:963:43: error: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 6 [-Werror=format-truncation=]
963 | snprintf(name, sizeof(name), "port%d", slot);
| ^~
drivers/pci/controller/pcie-mediatek.c:963:38: note: directive argument in the range [0, 2147483647]
963 | snprintf(name, sizeof(name), "port%d", slot);
| ^~~~~~~~
drivers/pci/controller/pcie-mediatek.c:963:9: note: ‘snprintf’ output between 6 and 15 bytes into a destination of size 10
963 | snprintf(name, sizeof(name), "port%d", slot);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Stable-dep-of: ebc1d9906894 ("PCI: mediatek: Use actual physical address instead of virt_to_phys()")
--- drivers/pci/controller/pcie-mediatek.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pcie-mediatek.c +1 -1
@@ -916,7 +916,7 @@ static int mtk_pcie_parse_port(struct mtk_pcie *pcie,struct mtk_pcie_port *port;struct device *dev = pcie->dev;struct platform_device *pdev =to_platform_device (dev); -char name[10 ]; +char name[20 ];int err; port =devm_kzalloc (dev,sizeof (*port),GFP_KERNEL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 534/1276 PCI: mediatek: Use actual physical address instead of virt_to_phys()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit ebc1d9906894703286d12306a6f242d90cfb49e8 ]
The driver previously used virt_to_phys() on the ioremapped register base (port->base) to compute the MSI message address. Using virt_to_phys() on an IO mapped address is incorrect because it expects a kernel virtual address.
To fix it, store the physical start of the I/O register region in mtk_pcie_port->phys_base and use it to build the MSI address. This replaces the incorrect virt_to_phys() usage and ensures MSI addresses are generated correctly.
--- drivers/pci/controller/pcie-mediatek.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/pci/controller/pcie-mediatek.c +13 -3
@@ -165,6 +165,7 @@ struct mtk_pcie_soc {/** * struct mtk_pcie_port - PCIe port information * @base: IO mapped register base +* @phys_base: Physical address of the I/O register base region * @list: port list * @pcie: pointer to PCIe host info * @reset: pointer to port reset control
@@ -187,6 +188,7 @@ struct mtk_pcie_soc {*/ struct mtk_pcie_port {void __iomem *base; +phys_addr_t phys_base;struct list_head list;struct mtk_pcie *pcie;struct reset_control *reset;
@@ -397,7 +399,7 @@ static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)phys_addr_t addr;/* MT2712/MT7622 only support 32-bit MSI addresses */ - addr =virt_to_phys (port->base +PCIE_MSI_VECTOR ); + addr = port->phys_base +PCIE_MSI_VECTOR ; msg->address_hi =0 ; msg->address_lo =lower_32_bits (addr);
@@ -513,7 +515,7 @@ static void mtk_pcie_enable_msi(struct mtk_pcie_port *port)u32 val;phys_addr_t msg_addr; - msg_addr =virt_to_phys (port->base +PCIE_MSI_VECTOR ); + msg_addr = port->phys_base +PCIE_MSI_VECTOR ; val =lower_32_bits (msg_addr);writel (val, port->base +PCIE_IMSI_ADDR );
@@ -916,6 +918,7 @@ static int mtk_pcie_parse_port(struct mtk_pcie *pcie,struct mtk_pcie_port *port;struct device *dev = pcie->dev;struct platform_device *pdev =to_platform_device (dev); +struct resource *res;char name[20 ];int err;
@@ -924,7 +927,14 @@ static int mtk_pcie_parse_port(struct mtk_pcie *pcie,return -ENOMEM ;snprintf (name,sizeof (name),"port%d" , slot); - port->base =devm_platform_ioremap_resource_byname (pdev, name); + res =platform_get_resource_byname (pdev,IORESOURCE_MEM , name); +if (!res) { +dev_err (dev,"failed to get port%d base\n" , slot); +return -EINVAL ; + } + + port->phys_base = res->start; + port->base =devm_ioremap_resource (&pdev->dev, res);if (IS_ERR (port->base)) {dev_err (dev,"failed to map port%d base\n" , slot);return PTR_ERR (port->base);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 535/1276 Revert "PCI/MSI: Unmap MSI-X region on error"
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuanhe Shu <[email protected]>
[ Upstream commit f64e03da0d83cb173743888bff4a7e61476a8fc2 ]
This reverts commit 1a8d4c6ecb4c81261bcdf13556abd4a958eca202.
Commit 1a8d4c6ecb4c ("PCI/MSI: Unmap MSI-X region on error") added an iounmap(dev->msix_base) on the error path of msix_capability_init() to release the MSI-X region when msix_setup_interrupts() fails.
When msix_setup_interrupts() fails, the call chain is:
msix_setup_interrupts()
-> __msix_setup_interrupts()
struct pci_dev *dev __free(free_msi_irqs) = __dev;
...
return ret; // __free cleanup fires on errorThe __free(free_msi_irqs) cleanup calls pci_free_msi_irqs(), which already handles the unmap:
void pci_free_msi_irqs(struct pci_dev *dev)
{
pci_msi_teardown_msi_irqs(dev);
if (dev->msix_base) {
iounmap(dev->msix_base); // already unmapped here
dev->msix_base = NULL; // and set to NULL
}
}So dev->msix_base is unmapped and set to NULL before msix_setup_interrupts() returns to msix_capability_init(). The "goto out_unmap" introduced by commit 1a8d4c6ecb4c ("PCI/MSI: Unmap MSI-X region on error") then calls iounmap() a second time on a NULL pointer.
This was reproduced on Intel Emerald Rapids (192 CPUs) while running tools/testing/selftests/kexec/test_kexec_jump.sh:
WARNING: CPU#44 at iounmap+0x2a/0xe0
RIP: 0010:iounmap+0x2a/0xe0 RDI: 0000000000000000 Call Trace: msix_capability_init+0x317/0x3f0 __pci_enable_msix_range+0x21d/0x2c0 pci_alloc_irq_vectors_affinity+0xa9/0x130 nvme_setup_io_queues+0x2a8/0x420 [nvme] nvme_reset_work+0x151/0x340 [nvme] ...
RDI=0 confirms iounmap() is called with NULL.
Restore the original "goto out_disable" and leave the unmap to the existing __free(free_msi_irqs) cleanup.
--- drivers/pci/msi/msi.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pci/msi/msi.c +1 -3
@@ -739,7 +739,7 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, ret =msix_setup_interrupts (dev, entries, nvec, affd);if (ret) - goto out_unmap; + goto out_disable;/* Disable INTX */ pci_intx_for_msi (dev,0 );
@@ -760,8 +760,6 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,pcibios_free_irq (dev);return 0 ; -out_unmap: -iounmap (dev->msix_base); out_disable: dev->msix_enabled =0 ;pci_msix_clear_and_set_ctrl (dev,PCI_MSIX_FLAGS_MASKALL |PCI_MSIX_FLAGS_ENABLE ,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 536/1276 security/apparmor/apparmorfs.c: conditionally compile get_loaddata_common_ref()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Morton <[email protected]>
[ Upstream commit d62d9bfe050f44f772d05a32079dba3e3523ab2a ]
Some config did this:
security/apparmor/apparmorfs.c:177:28: warning: 'get_loaddata_common_ref' defined but not used [-Wunused-function]
177 | static struct aa_loaddata *get_loaddata_common_ref(struct aa_common_ref *ref)
get_loaddata_common_ref() is only used ifCONFIG_SECURITY_APPARMOR_EXPORT_BINARY=y.
(Or of course move the function into that block if maintainers perfer)
--- security/apparmor/apparmorfs.c | 2 ++ 1 file changed, 2 insertions(+)
security/apparmor/apparmorfs.c +2 -0
@@ -174,6 +174,7 @@ static struct aa_proxy *get_proxy_common_ref(struct aa_common_ref *ref)return NULL ; } +#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY static struct aa_loaddata *get_loaddata_common_ref (struct aa_common_ref *ref) {if (ref)
@@ -181,6 +182,7 @@ static struct aa_loaddata *get_loaddata_common_ref(struct aa_common_ref *ref) count)); return NULL; } +#endif static void aa_put_common_ref (struct aa_common_ref *ref) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 537/1276 apparmor: check label build before no_new_privs test
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit a58cafd38b46fb1a2220e2fbbcfe291ea75fa147 ]
aa_change_profile() builds a replacement label with fn_label_build_in_scope() before the no_new_privs subset check. The build helper can fail and return NULL or an ERR_PTR, but the result was passed to aa_label_is_unconfined_subset() before the existing IS_ERR_OR_NULL() check.
Reuse the existing target-label build failure handling immediately after the build. This preserves the current audit handling while preventing the subset helper from dereferencing an invalid label.
--- security/apparmor/domain.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
security/apparmor/domain.c +15 -10
@@ -1471,6 +1471,8 @@ int aa_change_profile(const char *fqname, int flags) new =fn_label_build_in_ns (label, profile,GFP_KERNEL ,aa_get_label (target),aa_get_label (&profile->label)); +if (IS_ERR_OR_NULL (new)) + goto build_fail;/* * no new privs prevents domain transitions that would * reduce restrictions.
@@ -1488,16 +1490,8 @@ int aa_change_profile(const char *fqname, int flags)/* only transition profiles in the current ns */ if (stack) new =aa_label_merge (label, target,GFP_KERNEL ); -if (IS_ERR_OR_NULL (new)) { - info ="failed to build target label" ; -if (!new) - error = -ENOMEM ; -else - error =PTR_ERR (new); - new =NULL ; - perms.allow =0 ; - goto audit; - } +if (IS_ERR_OR_NULL (new)) + goto build_fail; error =aa_replace_current_label (new); }else {if (new) {
@@ -1509,6 +1503,17 @@ int aa_change_profile(const char *fqname, int flags)aa_set_current_onexec (target, stack); } + goto audit; + +build_fail: + info ="failed to build target label" ; +if (!new) + error = -ENOMEM ; +else + error =PTR_ERR (new); + new =NULL ; + perms.allow =0 ; + audit: error = fn_for_each_in_ns(label, profile, aa_audit_file(subj_cred,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 538/1276 apparmor: aa_label_alloc use aa_label_free on alloc failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zygmunt Krynicki <[email protected]>
[ Upstream commit 654fe7505dc6889724d4094fa64f89991afabfc3 ]
aa_label_alloc() allocates a secid before allocating or taking the label proxy. If the later proxy step fails, the error path only freed the label memory, leaking any resources initialized by aa_label_init().
Use aa_label_free() on the failure path so partially initialized labels release their secid and other label resources before the backing memory is freed.
--- security/apparmor/label.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/apparmor/label.c +1 -1
@@ -454,7 +454,7 @@ struct aa_label *aa_label_alloc(int size, struct aa_proxy *proxy, gfp_t gfp)return new; fail: -kfree (new); +aa_label_free (new);return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 539/1276 apparmor: fix rawdata_f_data implicit flex array
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
[ Upstream commit ad213bbbc0e3e270ce7df2d9d80d4ce3826993d7 ]
rawdata_f_data has a blob of data that is allocated at its end but not explicitly declared. Makes sure it is correctly declared as a flex_rray.
--- security/apparmor/apparmorfs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
security/apparmor/apparmorfs.c +3 -4
@@ -71,10 +71,10 @@struct rawdata_f_data {struct aa_loaddata *loaddata; + DECLARE_FLEX_ARRAY(char, data); };#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY -#define RAWDATA_F_DATA_BUF (p) (char *)(p + 1)static void rawdata_f_data_free (struct rawdata_f_data *private) {
@@ -1434,7 +1434,7 @@ static ssize_t rawdata_read(struct file *file, char __user *buf, size_t size,struct rawdata_f_data *private = file->private_data;return simple_read_from_buffer (buf, size, ppos, -RAWDATA_F_DATA_BUF (private), + private->data, private->loaddata->size); }
@@ -1467,8 +1467,7 @@ static int rawdata_open(struct inode *inode, struct file *file) private->loaddata = loaddata; error =decompress_zstd (loaddata->data, loaddata->compressed_size, -RAWDATA_F_DATA_BUF (private), - loaddata->size); + private->data, loaddata->size);if (error) goto fail_decompress;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 540/1276 apparmor: grab ns lock and refresh when looking up changehat child profiles
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryan Lee <[email protected]>
[ Upstream commit 32e92764d6f8d251c1bca62be33793287b453a81 ]
There was a race condition involving change_hat and profile replacement in which replacement of the parent profile during a changehat operation could result in the list of children becoming empty and the changehat operation failing. To prevent this:
- grab the namespace lock until we've built the hat transition, and
- use aa_get_newest_profile to avoid using stale profile objects.
--- security/apparmor/domain.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
security/apparmor/domain.c +31 -2
@@ -12,6 +12,7 @@#include <linux/fs.h> #include <linux/file.h> #include <linux/mount.h> +#include <linux/mutex.h> #include <linux/syscalls.h> #include <linux/personality.h> #include <linux/xattr.h>
@@ -1068,6 +1069,7 @@ static struct aa_label *change_hat(const struct cred *subj_cred, int count, int flags) {struct aa_profile *profile, *root, *hat =NULL ; +struct aa_ns *ns, *new_ns;struct aa_label *new;struct label_it it;bool sibling = false;
@@ -1078,6 +1080,32 @@ static struct aa_label *change_hat(const struct cred *subj_cred,AA_BUG (!hats);AA_BUG (count <1 ); +/* +* Acquire the newest label and then hold the lock until we choose a +* hat, so that profile replacement doesn't atomically truncate the +* list of potential hats. Because we are getting the namespaces from +* the profiles and label, we can rely on the namespaces being live +* and avoid incrementing their refcounts while grabbing the lock. +*/ + label =aa_get_label (label); + ns =labels_ns (label); + +retry: +mutex_lock_nested (&ns->lock, ns->level); +if (label_is_stale (label)) { + new =aa_get_newest_label (label); + new_ns =labels_ns (new); +if (new_ns != ns) { +aa_put_label (new); +mutex_unlock (&ns->lock); + ns = new_ns; + label = new; + goto retry; + } +aa_put_label (label); + label = new; + } +if (PROFILE_IS_HAT (labels_profile (label))) sibling = true;
@@ -1086,7 +1114,7 @@ static struct aa_label *change_hat(const struct cred *subj_cred, name = hats[i];label_for_each_in_ns (it,labels_ns (label), label, profile) {if (sibling &&PROFILE_IS_HAT (profile)) { - root =aa_get_profile_rcu (&profile->parent); + root =aa_get_profile (profile->parent); }else if (!sibling && !PROFILE_IS_HAT (profile)) { root =aa_get_profile (profile); }else {/* conflicting change type */
@@ -1146,6 +1174,7 @@ static struct aa_label *change_hat(const struct cred *subj_cred, GLOBAL_ROOT_UID, info, error); } } +mutex_unlock (&ns->lock);return ERR_PTR (error); build:
@@ -1158,7 +1187,7 @@ static struct aa_label *change_hat(const struct cred *subj_cred, error = -ENOMEM ; goto fail; }/* else if (IS_ERR) build_change_hat has logged error so return new */ - +mutex_unlock (&ns->lock);return new; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 541/1276 apparmor: fix potential UAF in aa_replace_profiles
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maxime Bélair <[email protected]>
[ Upstream commit 7b42f95813dc9ceb6bda35afcf914630909a19f9 ]
The function aa_replace_profiles was accessing udata->size after calling aa_put_loaddata(udata), causing a potential UAF.
Fixed this by saving the size to a local variable before dropping the reference.
--- security/apparmor/policy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
security/apparmor/policy.c +3 -1
@@ -1327,13 +1327,15 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,mutex_unlock (&ns->lock); out: +ssize_t udata_sz = udata->size; +aa_put_ns (ns);aa_put_profile_loaddata (udata);kfree (ns_name);if (error)return error; -return udata->size; +return udata_sz; fail_lock:mutex_unlock (&ns->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 542/1276 apparmor: remove or add symlinks to rawdata according to export_binary
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Georgia Garcia <[email protected]>
[ Upstream commit 59fe6fbc4cd45582bc8893de0a382a36562317b3 ]
When the export_binary parameter is set, then rawdata is available and there should be a symbolic link for the rawdata in the profile directory in apparmorfs. If the parameter is unset, then the symlinks should not exist.
The issue arises when changing the value of export_binary on runtime and replacing profiles. If export_binary was set when the profile was originally loaded, then changed to 0 and the profile was reloaded, then the symbolic links would still exist but would return ENOENT because the rawdata no longer exists.
On the opposite side, if export_binary was unset when the profile was originally loaded, then changed to 1 and the profile was reloaded, then the symbolic links would not exist, even though the rawdata does.
--- security/apparmor/apparmorfs.c | 102 +++++++++++++++++++------ security/apparmor/include/apparmorfs.h | 12 +++ security/apparmor/policy.c | 15 ++++ 3 files changed, 104 insertions(+), 25 deletions(-)
security/apparmor/apparmorfs.c +77 -25
@@ -1751,6 +1751,80 @@ static const struct inode_operations rawdata_link_abi_iops = {static const struct inode_operations rawdata_link_data_iops = { .get_link = rawdata_get_link_data, }; + +/* +* Requires: @profile->ns->lock held +*/ +void __aa_remove_rawdata_symlink_dents (struct aa_profile *profile) +{ +aafs_remove (profile->dents[AAFS_PROF_RAW_HASH ]); + profile->dents[AAFS_PROF_RAW_HASH ] =NULL ; +aafs_remove (profile->dents[AAFS_PROF_RAW_ABI ]); + profile->dents[AAFS_PROF_RAW_ABI ] =NULL ; +aafs_remove (profile->dents[AAFS_PROF_RAW_DATA ]); + profile->dents[AAFS_PROF_RAW_DATA ] =NULL ; +} + +static inline int create_symlink_dent (struct aa_profile *profile, +const char *name, +enum aafs_prof_type type, +const struct inode_operations *iops) +{ +struct dentry *dent =NULL ; +struct dentry *dir =prof_dir (profile); + +if (profile->dents[type]) +return 0 ; + + dent =aafs_create (name,S_IFLNK |0444 , dir, + &profile->label.proxy->count,NULL ,NULL , iops); +if (IS_ERR (dent)) +return PTR_ERR (dent); + + profile->dents[type] = dent; +return 0 ; +} + +/* +* Requires: @profile->ns->lock held +*/ +int __aa_create_rawdata_symlink_dents (struct aa_profile *profile) +{ +int error; + +if (!profile || + (profile->dents[AAFS_PROF_RAW_HASH ] && + profile->dents[AAFS_PROF_RAW_ABI ] && + profile->dents[AAFS_PROF_RAW_DATA ])) +return 0 ; + +if (!profile->rawdata) +return 0 ; + +if (aa_g_hash_policy) { + error =create_symlink_dent (profile,"raw_sha256" , +AAFS_PROF_RAW_HASH , + &rawdata_link_sha256_iops); +if (error) +return error; + } + + error =create_symlink_dent (profile,"raw_abi" , +AAFS_PROF_RAW_ABI , + &rawdata_link_abi_iops); +if (error) +return error; + + + error =create_symlink_dent (profile,"raw_data" , +AAFS_PROF_RAW_DATA , + &rawdata_link_data_iops); +if (error) +return error; + +return 0 ; +} +#endif /* CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */ /*
@@ -1826,31 +1900,9 @@ int __aafs_profile_mkdir(struct aa_profile *profile, struct dentry *parent) profile->dents[AAFS_PROF_HASH ] = dent; } -#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY -if (profile->rawdata) { -if (aa_g_hash_policy) { - dent =aafs_create ("raw_sha256" ,S_IFLNK |0444 , dir, - &profile->label.proxy->count,NULL , -NULL , &rawdata_link_sha256_iops); -if (IS_ERR (dent)) - goto fail; - profile->dents[AAFS_PROF_RAW_HASH ] = dent; - } - dent =aafs_create ("raw_abi" ,S_IFLNK |0444 , dir, - &profile->label.proxy->count,NULL ,NULL , - &rawdata_link_abi_iops); -if (IS_ERR (dent)) - goto fail; - profile->dents[AAFS_PROF_RAW_ABI ] = dent; - - dent =aafs_create ("raw_data" ,S_IFLNK |0444 , dir, - &profile->label.proxy->count,NULL ,NULL , - &rawdata_link_data_iops); -if (IS_ERR (dent)) - goto fail; - profile->dents[AAFS_PROF_RAW_DATA ] = dent; - } -#endif /*CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */ + error =__aa_create_rawdata_symlink_dents (profile); +if (error) + goto fail2;list_for_each_entry (child, &profile->base.profiles, base.list) { error =__aafs_profile_mkdir (child,prof_child_dir (profile));
security/apparmor/include/apparmorfs.h +12 -0
@@ -118,6 +118,8 @@ struct aa_loaddata;#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY void __aa_fs_remove_rawdata (struct aa_loaddata *rawdata);int __aa_fs_create_rawdata (struct aa_ns *ns,struct aa_loaddata *rawdata); +void __aa_remove_rawdata_symlink_dents (struct aa_profile *profile); +int __aa_create_rawdata_symlink_dents (struct aa_profile *profile);#else static inline void __aa_fs_remove_rawdata (struct aa_loaddata *rawdata) {
@@ -129,6 +131,16 @@ static inline int __aa_fs_create_rawdata(struct aa_ns *ns, {return 0 ; } + +static inline void __aa_remove_rawdata_symlink_dents (struct aa_profile *profile) +{ +/* empty stub */ +} + +static inline int __aa_create_rawdata_symlink_dents (struct aa_profile *profile) +{ +return 0 ; +}#endif /* CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */ #endif /* __AA_APPARMORFS_H */
security/apparmor/policy.c +15 -0
@@ -1298,6 +1298,16 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label, goto skip; } +if (!aa_g_export_binary) { +if (ent->old && ent->old->rawdata && + ent->old->dents[AAFS_LOADDATA_DIR ]) { +/* remove rawdata symlinks because the symlink +* target will be removed +*/ +__aa_remove_rawdata_symlink_dents (ent->old); + } + } +/* * TODO: finer dedup based on profile range in data. Load set * can differ but profile may remain unchanged
@@ -1308,6 +1318,11 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,if (ent->old) {share_name (ent->old, ent->new);__replace_profile (ent->old, ent->new); +if (aa_g_export_binary) { +/* recreate rawdata symlinks */ +if (!ent->old->rawdata) +__aa_create_rawdata_symlink_dents (ent->new); + } }else {struct list_head *lh;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 543/1276 apparmor: aa_getprocattr free procattr leak on format failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zygmunt Krynicki <[email protected]>
[ Upstream commit fea23bf73f0cae8ccb1d0684e4a3003874771f41 ]
aa_getprocattr() allocates the output string before rendering the label into it. If the second aa_label_snxprint() call fails, the function returned without freeing that allocation.
Free and clear the output pointer on the uncommon formatting failure path before dropping the namespace reference.
--- security/apparmor/procattr.c | 2 ++ 1 file changed, 2 insertions(+)
security/apparmor/procattr.c +2 -0
@@ -54,6 +54,8 @@ int aa_getprocattr(struct aa_label *label, char **string, bool newline)FLAG_SHOW_MODE |FLAG_VIEW_SUBNS | FLAG_HIDDEN_UNCONFINED);if (len <0 ) { +kfree (*string); + *string =NULL ;aa_put_ns (current_ns);return len; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 544/1276 apparmor: put secmark label after secid lookup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zygmunt Krynicki <[email protected]>
[ Upstream commit 340372688bb87da45ff8d4e2f82ccfd1b64c65ff ]
apparmor_secmark_init() parses a configured secmark label to obtain its secid. aa_label_strn_parse() returns a refcounted label, but the success path kept that reference after copying the secid.
--- security/apparmor/net.c | 1 + 1 file changed, 1 insertion(+)
security/apparmor/net.c +1 -0
@@ -217,6 +217,7 @@ static int apparmor_secmark_init(struct aa_secmark *secmark)return PTR_ERR (label); secmark->secid = label->secid; +aa_put_label (label);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 545/1276 workqueue: Add new WQ_PERCPU flag
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Crivellari <[email protected]>
[ Upstream commit 930c2ea566aff59e962c50b2421d5fcc3b98b8be ]
Currently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistentcy cannot be addressed without refactoring the API.
This patch adds a new WQ_PERCPU flag to explicitly request the use of the per-CPU behavior. Both flags coexist for one release cycle to allow callers to transition their calls.
Once migration is complete, WQ_UNBOUND can be removed and unbound will become the implicit default.
tj: Merged doc patch.
Stable-dep-of: 527756cb9ebb ("i3c: master: Make hot-join workqueue freezable to block hot-join during suspend")
--- Documentation/core-api/workqueue.rst | 6 ++++++ include/linux/workqueue.h | 1 + 2 files changed, 7 insertions(+)
Documentation/core-api/workqueue.rst +6 -0
@@ -183,6 +183,12 @@ resources, scheduled and executed. BH work items cannot sleep. All other features such as delayed queueing, flushing and canceling are supported. +``WQ_PERCPU`` + Work items queued to a per-cpu wq are bound to a specific CPU. + This flag is the right choice when cpu locality is important. + + This flag is the complement of ``WQ_UNBOUND``. + ``WQ_UNBOUND`` Work items queued to an unbound wq are served by the special worker-pools which host workers which are not bound to any
include/linux/workqueue.h +1 -0
@@ -401,6 +401,7 @@ enum wq_flags {* http://thread.gmane.org/gmane.linux.kernel/1480396 */ WQ_POWER_EFFICIENT =1 <<7 , +WQ_PERCPU =1 <<8 ,/* bound to a specific cpu */ __WQ_DESTROYING =1 <<15 ,/* internal: workqueue is destroying */ __WQ_DRAINING = 1 << 16, /* internal: workqueue is draining */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 546/1276 i3c: master: add WQ_PERCPU to alloc_workqueue users
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Crivellari <[email protected]>
[ Upstream commit de53ad6ca49e5d73bba72d24b49ec5d40f33ee01 ]
Currently if a user enqueues a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistency cannot be addressed without refactoring the API.
alloc_workqueue() treats all queues as per-CPU by default, while unbound workqueues must opt-in via WQ_UNBOUND.
This default is suboptimal: most workloads benefit from unbound queues, allowing the scheduler to place worker threads where they’re needed and reducing noise when CPUs are isolated.
This continues the effort to refactor workqueue APIs, which began with the introduction of new workqueues and a new alloc_workqueue flag in:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
This change adds a new WQ_PERCPU flag to explicitly request alloc_workqueue() to be per-cpu when WQ_UNBOUND has not been specified.
With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND), any alloc_workqueue() caller that doesn’t explicitly specify WQ_UNBOUND must now use WQ_PERCPU.
Once migration is complete, WQ_UNBOUND can be removed and unbound will become the implicit default.
Stable-dep-of: 527756cb9ebb ("i3c: master: Make hot-join workqueue freezable to block hot-join during suspend")
--- drivers/i3c/master.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i3c/master.c +1 -1
@@ -2853,7 +2853,7 @@ int i3c_master_register(struct i3c_master_controller *master,if (ret) goto err_put_dev; - master->wq =alloc_workqueue ("%s" ,0 ,0 ,dev_name (parent)); + master->wq =alloc_workqueue ("%s" ,WQ_PERCPU ,0 ,dev_name (parent));if (!master->wq) { ret = -ENOMEM ; goto err_put_dev;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 547/1276 i3c: master: Make hot-join workqueue freezable to block hot-join during suspend
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 527756cb9ebb277dca12fff00af9fbb3b9ec8cc8 ]
The I3C master workqueue (master->wq) is used to defer work that needs thread context and the bus maintenance lock, most notably Hot Join processing (which calls i3c_master_do_daa() to assign dynamic addresses to newly joined devices).
Currently the workqueue keeps running across system suspend, which can race with the suspend path:
- do_daa() may execute after the controller has been suspended, issuing bus transactions on a powered-down or otherwise unusable controller.
- New I3C devices can be enumerated and added to the bus mid-suspend, registering driver model objects at a point where the I3C subsystem and its consumers are not prepared to handle them.
Mark the workqueue WQ_FREEZABLE so its workers are frozen for the duration of system suspend/hibernate and resumed afterwards. This naturally defers any pending or newly queued Hot Join work until the system (and the controller) is fully resumed, closing both races without adding explicit suspend/resume synchronization in the master drivers.
Update the kerneldoc for struct i3c_master_controller::wq to reflect that the workqueue is freezable.
--- drivers/i3c/master.c | 2 +- include/linux/i3c/master.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/i3c/master.c +1 -1
@@ -2853,7 +2853,7 @@ int i3c_master_register(struct i3c_master_controller *master,if (ret) goto err_put_dev; - master->wq =alloc_workqueue ("%s" ,WQ_PERCPU ,0 ,dev_name (parent)); + master->wq =alloc_workqueue ("%s" ,WQ_PERCPU |WQ_FREEZABLE ,0 ,dev_name (parent));if (!master->wq) { ret = -ENOMEM ; goto err_put_dev;
include/linux/i3c/master.h +1 -1
@@ -503,7 +503,7 @@ struct i3c_master_controller_ops {* @boardinfo.i2c: list of I2C boardinfo objects * @boardinfo: board-level information attached to devices connected on the bus * @bus: I3C bus exposed by this master -* @wq: workqueue which can be used by master +* @wq: freezable workqueue which can be used by master * drivers if they need to postpone operations that need to take place * in a thread context. Typical examples are Hot Join processing which * requires taking the bus lock in maintenance, which in turn, can only
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 548/1276 i3c: master: Prevent reuse of dynamic address on device add failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit b3ba8383da4d0cff15810e32ea785eceb0a80813 ]
i3c_master_add_i3c_dev_locked() is called after a device has already been assigned a dynamic address. If the function fails, the address remains marked as free and may be reallocated to another device, leading to address conflicts on the bus.
Ensure the address is not marked as free on failure, by updating the address slot state to prevent the address from being re-used.
Emit an error message to inform of the failure.
Opportunistically remove the !master check because it is impossible.
Note, directly resetting the device's dynamic address is no longer an option, since Direct RSTDAA was deprecated from I3C starting from version 1.1 and v1.1 (or later) target devices are meant to NACK it.
--- drivers/i3c/master.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/i3c/master.c +14 -5
@@ -2055,12 +2055,11 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,bool enable_ibi = false;int ret; -if (!master) -return -EINVAL ; - newdev =i3c_master_alloc_i3c_dev (master, &info); -if (IS_ERR (newdev)) -return PTR_ERR (newdev); +if (IS_ERR (newdev)) { + ret =PTR_ERR (newdev); + goto err_prevent_addr_reuse; + } ret =i3c_master_attach_i3c_dev (master, newdev);if (ret)
@@ -2182,6 +2181,16 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, err_free_dev:i3c_master_free_i3c_dev (newdev); +err_prevent_addr_reuse: +/* +* Although the device has not been added, the address has been +* assigned. Prevent the address from being used again. +*/ +if (i3c_bus_get_addr_slot_status (&master->bus, addr) ==I3C_ADDR_SLOT_FREE ) +i3c_bus_set_addr_slot_status (&master->bus, addr,I3C_ADDR_SLOT_I3C_DEV ); + +dev_err (&master->dev,"Failed to add I3C device at address %u, error %d\n" , addr, ret); +return ret; }EXPORT_SYMBOL_GPL (i3c_master_add_i3c_dev_locked);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 549/1276 apparmor: fix label can not be immediately before a declaration
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
[ Upstream commit 1ed40bd525c00d22af666016af9aef7167f8085f ]
Fix error reported by kernel test robot
security/apparmor/policy.c:1381:2: error: a label can only be part of a statement and a declaration is not a statement
All errors (new ones prefixed by >>):
security/apparmor/policy.c: In function 'aa_replace_profiles':
Quoted 1 line
Quoted 1 line
security/apparmor/policy.c:1381:2: error: a label can only be part
of a statement and a declaration is not a statement
ssize_t udata_sz = udata->size;
^~~~~--- security/apparmor/policy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
security/apparmor/policy.c +2 -1
@@ -1342,9 +1342,10 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,mutex_unlock (&ns->lock); out: +aa_put_ns (ns); +ssize_t udata_sz = udata->size; -aa_put_ns (ns);aa_put_profile_loaddata (udata);kfree (ns_name);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 550/1276 sparc: led: avoid trimming a newline from empty writes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 7eb475e8a738ee6fd1260aa59ddccb610fdd4300 ]
led_proc_write() duplicates up to LED_MAX_LENGTH bytes with memdup_user_nul() and then unconditionally inspects buf[count - 1] to strip a trailing newline. A zero-length write therefore reads one byte before the duplicated buffer.
The previous version rejected empty writes, but empty input already falls through to the existing default case and turns the LED off like any other unrecognized string. Preserve that behavior and only skip the newline trim when there is no input byte to inspect.
--- arch/sparc/kernel/led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/kernel/led.c +1 -1
@@ -78,7 +78,7 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer,return PTR_ERR (buf);/* work around \n when echo'ing into proc */ -if (buf[count -1 ] =='\n' ) +if (count >0 && buf[count -1 ] =='\n' ) buf[count -1 ] ='\0' ;/* before we change anything we want to stop any running timers,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 551/1276 perf maps: Add maps__mutate_mapping
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 75a4888b7029a1f98613aef91f517b2ee1f03d43 ]
During kernel ELF symbol parsing (dso__process_kernel_symbol), proc kallsyms image loading (dso__load_kernel_sym, dso__load_guest_kernel_sym), and dynamic kernel memory map alignment updates (machine__update_kernel_mmap), the loader directly modifies live virtual address boundary keys fields on map objects.
If these boundaries are mutated while the map pointer actively resides inside the parent maps cache array list (kmaps) outside of any lock closure, an unsafe concurrent window is exposed where parallel worker lookup threads (e.g., inside perf top) can mistakenly assume the cache remains sorted based on stale parameters, executing binary search queries (bsearch) across an unsorted range and triggering lookup failures.
Fix this by introducing maps__mutate_mapping() that explicitly acquires the parent maps write semaphore lock, executes an incoming mutation callback block to perform the field updates under lock protection, and invalidates the sorted tracking flags prior to releasing the write lock.
This guarantees synchronization invariants, closing the concurrent lookup race window. The adjacent module alignment pass inside machine__create_kernel_maps() is safely preserved as a high-performance lockless pass, as its invocation lifecycle bounds remain strictly single-threaded by contract during session initialization construction.
To safely support this unconditional down_write write lock mutator without recursive read-to-write self-deadlock upgrades during lazy symbol loading, we introduce a public maps__load_maps() API.
It copies map pointers under a brief read lock and force-loads all modules locklessly outside the lock. Callers (such as perf inject) must pre-load all kernel symbol maps up front at startup using maps__load_maps(), completely bypassing dynamic runtime mutations.
--- tools/perf/util/machine.c | 32 +++++--- tools/perf/util/maps.c | 148 ++++++++++++++++++++++++++++------- tools/perf/util/maps.h | 3 + tools/perf/util/symbol-elf.c | 41 ++++++---- tools/perf/util/symbol.c | 17 +++- 5 files changed, 183 insertions(+), 58 deletions(-)
tools/perf/util/machine.c +20 -12
@@ -1489,22 +1489,30 @@ static void machine__set_kernel_mmap(struct machine *machine,map__set_end (machine->vmlinux_map, ~0ULL ); } -static int machine__update_kernel_mmap (struct machine *machine, -u64 start,u64 end) +struct kernel_mmap_mutation_ctx { +u64 start; +u64 end; +}; + +static int kernel_mmap_mutate_cb (struct map *map,void *data) { -struct map *orig, *updated; -int err; +struct kernel_mmap_mutation_ctx *ctx = data; - orig = machine->vmlinux_map; - updated =map__get (orig); +map__set_start (map, ctx->start); +map__set_end (map, ctx->end); +if (ctx->start ==0 && ctx->end ==0 ) +map__set_end (map, ~0ULL ); +return 0 ; +} - machine->vmlinux_map = updated; -maps__remove (machine__kernel_maps (machine), orig); -machine__set_kernel_mmap (machine, start, end); - err =maps__insert (machine__kernel_maps (machine), updated); -map__put (orig); +static int machine__update_kernel_mmap (struct machine *machine, +u64 start,u64 end) +{ +struct kernel_mmap_mutation_ctx ctx = { .start = start, .end = end }; -return err; +return maps__mutate_mapping (machine__kernel_maps (machine), + machine->vmlinux_map, + kernel_mmap_mutate_cb, &ctx); }int machine__create_kernel_maps (struct machine *machine)
tools/perf/util/maps.c +121 -27
173 lines not on this page · raw message
tools/perf/util/maps.h +3 -0
@@ -55,8 +55,11 @@ void maps__set_unwind_libunwind_ops(struct maps *maps, const struct unwind_libunsize_t maps__fprintf (struct maps *maps,FILE *fp); +int maps__load_maps (struct maps *maps);int maps__insert (struct maps *maps,struct map *map);void maps__remove (struct maps *maps,struct map *map); +int maps__mutate_mapping (struct maps *maps,struct map *map, +int (*mutate_cb)(struct map *map,void *data),void *data);struct map *maps__find (struct maps *maps,u64 addr);struct symbol *maps__find_symbol (struct maps *maps,u64 addr,struct map **mapp);
tools/perf/util/symbol-elf.c +26 -15
54 lines not on this page · raw message
tools/perf/util/symbol.c +13 -4
@@ -42,6 +42,13 @@#include <symbol/kallsyms.h> #include <sys/utsname.h> +static int map_fixup_cb (struct map *map,void *data__maybe_unused ) +{ +map__fixup_start (map); +map__fixup_end (map); +return 0 ; +} +static int dso__load_kernel_sym (struct dso *dso,struct map *map);static int dso__load_guest_kernel_sym (struct dso *dso,struct map *map);static bool symbol__is_idle (const char *name);
@@ -2227,10 +2234,11 @@ static int dso__load_kernel_sym(struct dso *dso, struct map *map)free (kallsyms_allocated_filename);if (err >0 && !dso__is_kcore (dso)) { +struct maps *kmaps =map__kmaps (map); +dso__set_binary_type (dso,DSO_BINARY_TYPE__KALLSYMS );dso__set_long_name (dso,DSO__NAME_KALLSYMS , false); -map__fixup_start (map); -map__fixup_end (map); +maps__mutate_mapping (kmaps, map, map_fixup_cb,NULL ); }return err;
@@ -2270,10 +2278,11 @@ static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map)if (err >0 )pr_debug ("Using %s for symbols\n" , kallsyms_filename);if (err >0 && !dso__is_kcore (dso)) { +struct maps *kmaps =map__kmaps (map); +dso__set_binary_type (dso,DSO_BINARY_TYPE__GUEST_KALLSYMS );dso__set_long_name (dso, machine->mmap_name, false); -map__fixup_start (map); -map__fixup_end (map); +maps__mutate_mapping (kmaps, map, map_fixup_cb,NULL ); }return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 552/1276 perf symbols: Fix bswap copy-paste error for 32-bit ELF p_filesz
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 081b387c7397498c583b1ba7c2fdaf4c6da6b538 ]
filename__read_build_id() byte-swaps 32-bit ELF program headers on cross-endian files, but line 178 passes p_offset to bswap_32() instead of p_filesz:
hdrs.phdr32[i].p_filesz = bswap_32(hdrs.phdr32[i].p_offset);
This clobbers p_filesz with the already-swapped p_offset value. The 64-bit path on line 182 is correct and swaps p_filesz from p_filesz.
The consequence is that the PT_NOTE segment read uses the wrong size, which can cause either a short read (missing the build-id) or an oversized read (reading past the segment into adjacent data).
Fix by swapping the correct field.
--- tools/perf/util/symbol-minimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/symbol-minimal.c +1 -1
@@ -168,7 +168,7 @@ int filename__read_build_id(const char *filename, struct build_id *bid)if (elf32) { hdrs.phdr32[i].p_type =bswap_32 (hdrs.phdr32[i].p_type); hdrs.phdr32[i].p_offset =bswap_32 (hdrs.phdr32[i].p_offset); - hdrs.phdr32[i].p_filesz =bswap_32 (hdrs.phdr32[i].p_offset); + hdrs.phdr32[i].p_filesz =bswap_32 (hdrs.phdr32[i].p_filesz); }else { hdrs.phdr64[i].p_type =bswap_32 (hdrs.phdr64[i].p_type); hdrs.phdr64[i].p_offset =bswap_64 (hdrs.phdr64[i].p_offset);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 553/1276 perf symbols: Validate p_filesz before use in filename__read_build_id()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 2a3716544359d4312c81b0fa909a13301186da17 ]
filename__read_build_id() stores ELF p_filesz in a ssize_t variable. A crafted 32-bit ELF with p_filesz = 0xFFFFFFFF produces ssize_t value -1. The comparison p_filesz > buf_size evaluates false because signed -1 is less than any non-negative buf_size, so the realloc is skipped and buf remains NULL.
The subsequent read(fd, NULL, -1) returns -1, which equals p_filesz, passing the error check. read_build_id() then dereferences the NULL buffer.
Add an explicit check for p_filesz <= 0 before using the value, catching both zero-length and sign-wrapped negative sizes from crafted ELF files.
--- tools/perf/util/symbol-minimal.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/symbol-minimal.c +3 -0
@@ -179,6 +179,9 @@ int filename__read_build_id(const char *filename, struct build_id *bid)continue ; p_filesz = elf32 ? hdrs.phdr32[i].p_filesz : hdrs.phdr64[i].p_filesz; +/* ssize_t can go negative with crafted ELF p_filesz values */ +if (p_filesz <=0 ) +continue ;if (p_filesz > buf_size) {void *tmp;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 554/1276 perf symbols: Break infinite loop on zero-filled notes in sysfs__read_build_id()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 063c647b24f640657d6d9e2e90d620ea3ee19ae6 ]
sysfs__read_build_id() iterates ELF note headers from sysfs files in a while(1) loop. If the file contains a zero-filled note header (both n_namesz and n_descsz are 0), the code computes n = namesz + descsz = 0 and calls read(fd, bf, 0). read() with count 0 returns 0, which matches the expected (ssize_t)n value, so the error check passes and the loop repeats — reading the same zero bytes and spinning forever.
This can happen with corrupted or zero-padded sysfs pseudo-files.
Add a check for n == 0 before the read, since no valid ELF note has both name and description of zero length.
--- tools/perf/util/symbol-elf.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/symbol-elf.c +3 -0
@@ -1092,6 +1092,9 @@ int sysfs__read_build_id(const char *filename, struct build_id *bid) }else { n = namesz + descsz; } +/* no valid note has both namesz and descsz zero */ +if (n ==0 ) +break ;if (read (fd, bf, n) != (ssize_t )n)break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 555/1276 perf tools: Use snprintf() for root_dir path construction
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 7b0df6f4d498b1608afccfd6dffb264e6da91693 ]
get_kernel_version() in machine.c and dso__load_guest_kernel_sym() in symbol.c use sprintf() to construct paths by prepending root_dir to "/proc/version" and "/proc/kallsyms" respectively. Both write into PATH_MAX stack buffers, but root_dir comes from --guestmount or KVM configuration and is not length-checked. A root_dir at or near PATH_MAX causes a stack buffer overflow.
Switch to snprintf() with sizeof(path) to prevent overflow.
--- tools/perf/util/machine.c | 2 +- tools/perf/util/symbol.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +1 -1
@@ -1294,7 +1294,7 @@ static char *get_kernel_version(const char *root_dir)char *name, *tmp;const char *prefix ="Linux version " ; -sprintf (version,"%s/proc/version" , root_dir); +snprintf (version,sizeof (version),"%s/proc/version" , root_dir); file =fopen (version,"r" );if (!file)return NULL ;
tools/perf/util/symbol.c +1 -1
@@ -2270,7 +2270,7 @@ static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map)if (!kallsyms_filename)return -1 ; }else { -sprintf (path,"%s/proc/kallsyms" , machine->root_dir); +snprintf (path,sizeof (path),"%s/proc/kallsyms" , machine->root_dir); kallsyms_filename = path; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 556/1276 perf bpf: Validate func_info_rec_size and sub_id in synthesize_bpf_prog_name()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 10b3c3d63ecc17c6acb855bac5f40367f1115765 ]
synthesize_bpf_prog_name() computes a pointer into the func_info array using sub_id * info->func_info_rec_size without validating either value. Both come from perf.data and are untrusted:
- A func_info_rec_size smaller than sizeof(struct bpf_func_info) means the finfo pointer would reference a truncated entry, reading past it into adjacent data.
- A sub_id >= nr_func_info computes an offset past the func_info buffer, causing an out-of-bounds read.
Add bounds checks for both values before computing the pointer offset. When validation fails, fall through to the non-BTF name path instead of reading garbage.
--- tools/perf/util/bpf-event.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/bpf-event.c +3 -1
@@ -135,7 +135,9 @@ static int synthesize_bpf_prog_name(char *buf, int size, name_len =scnprintf (buf, size,"bpf_prog_" ); name_len +=snprintf_hex (buf + name_len, size - name_len, prog_tags[sub_id],BPF_TAG_SIZE ); -if (btf) { +if (btf && + info->func_info_rec_size >=sizeof (*finfo) && + sub_id < info->nr_func_info) { finfo = func_infos + sub_id * info->func_info_rec_size; t =btf__type_by_id (btf, finfo->type_id);if (t)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 557/1276 perf bpf: Bounds-check array offsets in bpil_offs_to_addr()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 033e85edfbf271f92979d2a39aeaf40f8472a795 ]
bpil_offs_to_addr() converts offsets stored in perf.data's bpf_prog_info_linear structure into heap pointers by adding the offset to the data allocation base. The offsets come from untrusted file input and are not validated against data_len.
If an offset exceeds data_len, the computed address points outside the allocated data buffer. Callers like synthesize_bpf_prog_name() then dereference prog_tags[sub_id] or func_info pointers, reading arbitrary heap memory.
Add a bounds check: when an offset exceeds data_len, zero the field and skip the conversion. This prevents out-of-bounds pointer construction from crafted perf.data files.
--- tools/perf/util/bpf-utils.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tools/perf/util/bpf-utils.c +16 -0
@@ -264,12 +264,28 @@ void bpil_offs_to_addr(struct perf_bpil *info_linear)for (i =PERF_BPIL_FIRST_ARRAY ; i <PERF_BPIL_LAST_ARRAY ; ++i) {const struct bpil_array_desc *desc = &bpil_array_desc[i];__u64 addr, offs; +__u32 count, size;if ((info_linear->arrays & (1UL << i)) ==0 )continue ; offs =bpf_prog_info_read_offset_u64 (&info_linear->info, desc->array_offset); + count =bpf_prog_info_read_offset_u32 (&info_linear->info, + desc->count_offset); + size =bpf_prog_info_read_offset_u32 (&info_linear->info, + desc->size_offset); +/* offset and extent from perf.data are untrusted — keep within data[] */ +if (offs >= info_linear->data_len || + (u64 )count * size > info_linear->data_len - offs) { +bpf_prog_info_set_offset_u64 (&info_linear->info, + desc->array_offset,0 ); +bpf_prog_info_set_offset_u32 (&info_linear->info, + desc->count_offset,0 ); +/* clear the bit so bpil_addr_to_offs() won't reverse a zeroed address */ + info_linear->arrays &= ~(1UL << i); +continue ; + } addr = offs +ptr_to_u64 (info_linear->data);bpf_prog_info_set_offset_u64 (&info_linear->info, desc->array_offset, addr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 558/1276 perf: Remove redundant kernel.h include
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Yan <[email protected]>
[ Upstream commit 7a0ba3891104da77cfd1a16d41699e0fdf45603a ]
Now that the bitfield dependency is resolved, the explicit inclusion of kernel.h is no longer needed.
Remove the redundant include.
Stable-dep-of: 542e88a4c6f7 ("perf cs-etm: Reject CPU IDs that would overflow signed comparison")
--- tools/perf/arch/arm64/util/header.c | 1 - tools/perf/util/cs-etm.c | 1 - 2 files changed, 2 deletions(-)
tools/perf/arch/arm64/util/header.c +0 -1
@@ -1,4 +1,3 @@ -#include <linux/kernel.h> #include <linux/bits.h> #include <linux/bitfield.h> #include <stdio.h>
tools/perf/util/cs-etm.c +0 -1
@@ -6,7 +6,6 @@* Author: Mathieu Poirier <[email protected]> */ -#include <linux/kernel.h> #include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/coresight-pmu.h>
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 559/1276 perf cs-etm: Reject CPU IDs that would overflow signed comparison
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 542e88a4c6f7b6edd1326ce767d4cb3c2ea9d61d ]
metadata[j][CS_ETM_CPU] is a u64 from perf.data, but the comparison with max_cpu casts it to (int). A crafted value like 0xFFFFFFFF becomes -1 after the cast, which compares less than max_cpu (0), so the queue array is never sized to accommodate it. When the value is later passed to cs_etm__get_queue(), it indexes queue_array with the original large value, causing an out-of-bounds access.
Validate that CS_ETM_CPU fits in an int before using it in the signed comparison.
--- tools/perf/util/cs-etm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/cs-etm.c +8 -1
@@ -6,6 +6,7 @@* Author: Mathieu Poirier <[email protected]> */ +#include <limits.h> #include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/coresight-pmu.h>
@@ -3465,7 +3466,13 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, goto err_free_metadata; } -if ((int ) metadata[j][CS_ETM_CPU ] > max_cpu) +/* CPU id comes from perf.data and must fit max_cpu + 1 without overflow */ +if (metadata[j][CS_ETM_CPU ] >=INT_MAX ) { + err = -EINVAL ; + goto err_free_metadata; + } + +if ((int )metadata[j][CS_ETM_CPU ] > max_cpu) max_cpu = metadata[j][CS_ETM_CPU ]; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 560/1276 gpio: mlxbf3: fail probe if gpiochip registration fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 0482862a90169f4daaba0ed31a85d8304bf51e04 ]
mlxbf3_gpio_probe() logs a devm_gpiochip_add_data() failure but still returns success. That leaves the platform device bound even though the GPIO chip was not registered.
Return the registration error so probe failure matches the missing gpiochip state.
--- drivers/gpio/gpio-mlxbf3.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpio/gpio-mlxbf3.c +2 -1
@@ -252,7 +252,8 @@ static int mlxbf3_gpio_probe(struct platform_device *pdev) ret =devm_gpiochip_add_data (dev, &gs->gc, gs);if (ret) -dev_err_probe (dev, ret,"Failed adding memory mapped gpiochip\n" ); +return dev_err_probe (dev, ret, +"Failed adding memory mapped gpiochip\n" );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 561/1276 drm/i915: clear CRTC color blob pointers after dropping refs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 31f077088e0faae6be8377741f356dea1b94ba46 ]
intel_crtc_put_color_blobs() drops the CRTC color blob references, but leaves the corresponding pointers unchanged.
This can matter in intel_crtc_prepare_cleared_state(), which frees the old CRTC hw state before calling intel_dp_tunnel_atomic_clear_stream_bw(). The latter can fail while looking up the DP tunnel group state, for example with -EDEADLK.
If that happens, the function returns without completing the cleared state preparation. The failed atomic state will then be cleared by the atomic core and intel_crtc_free_hw_state() can be called again for the same state, dropping the same blob references again.
Clear the blob pointers after dropping the references so repeated cleanup of the same CRTC hw state is safe.
--- drivers/gpu/drm/i915/display/intel_atomic.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/i915/display/intel_atomic.c +6 -0
@@ -290,6 +290,12 @@ static void intel_crtc_put_color_blobs(struct intel_crtc_state *crtc_state)drm_property_blob_put (crtc_state->pre_csc_lut);drm_property_blob_put (crtc_state->post_csc_lut); + + crtc_state->hw.degamma_lut =NULL ; + crtc_state->hw.gamma_lut =NULL ; + crtc_state->hw.ctm =NULL ; + crtc_state->pre_csc_lut =NULL ; + crtc_state->post_csc_lut =NULL ; }void intel_crtc_free_hw_state (struct intel_crtc_state *crtc_state)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 562/1276 spi: dw: fix wrong BAUDR setting after resume
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jisheng Zhang <[email protected]>
[ Upstream commit 66b6605bcea7af7aca3d1d858b9c5f14903f9f9a ]
After resuming from suspend to ram, spi transfer stops working. Further debugging shows that the BAUDR register isn't correctly set, this is due to dws->current_freq doesn't match the HW BAUDR setting, specifically, the dws->current_freq equals to speed_hz, but BAUDR is 0. so the dw_spi_set_clk() in below code won't be called:
if (dws->current_freq != speed_hz) {
dw_spi_set_clk(dws, clk_div);
dws->current_freq = speed_hz;
}The mismatch comes from dw_spi_shutdown_chip() when suspending. Fix this mismatch by setting dws->current_freq to 0 as well when clearing BAUDR reg in dw_spi_shutdown_chip().
--- drivers/spi/spi-dw.h | 1 + 1 file changed, 1 insertion(+)
drivers/spi/spi-dw.h +1 -0
@@ -282,6 +282,7 @@ static inline void dw_spi_shutdown_chip(struct dw_spi *dws) {dw_spi_enable_chip (dws,0 );dw_spi_set_clk (dws,0 ); + dws->current_freq =0 ; }extern void dw_spi_set_cs (struct spi_device *spi,bool enable);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 563/1276 xfrm: Fix xfrm state cache insertion race
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Herbert Xu <[email protected]>
[ Upstream commit ddd3d0132920319ac426e12456013eadbae67e15 ]
The xfrm input state cache insertion code checks the validity of the state before acquiring the global xfrm_state_lock. Thus it's possible for someone else to kill the state after it passed the validity check, and then the insertion will add the dead state to the cache.
Fix this by moving the validity check inside the lock.
This entire function is called on the input path, where BH must be off (e.g., the caller of this function xfrm_input acquires its spinlocks without disabling BH).
So there is no need to disable BH here or take the RCU read lock. Remove both and replace them with an assertion that trips if BH is accidentally enabled on some future calling path.
--- net/xfrm/xfrm_state.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
net/xfrm/xfrm_state.c +14 -7
@@ -1144,9 +1144,11 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark,struct hlist_head *state_cache_input;struct xfrm_state *x =NULL ; +/* BH is always disabled on the input path. */ +lockdep_assert_in_softirq (); + state_cache_input =raw_cpu_ptr (net->xfrm.state_cache_input); -rcu_read_lock ();hlist_for_each_entry_rcu (x, state_cache_input, state_cache_input) { if (x->props.family != family || x->id.spi != spi ||
@@ -1164,20 +1166,25 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark,xfrm_hash_ptrs_get (net, &state_ptrs); x =__xfrm_state_lookup (&state_ptrs, mark, daddr, spi, proto, family); - -if (x && x->km.state ==XFRM_STATE_VALID ) { -spin_lock_bh (&net->xfrm.xfrm_state_lock); -if (hlist_unhashed (&x->state_cache_input)) { +if (x) { +spin_lock (&net->xfrm.xfrm_state_lock); +if (x->km.state !=XFRM_STATE_VALID ) { +/* +* The state is about to be destroyed. +* +* Don't add it to the cache but still +* return it to the caller. +*/ + }else if (hlist_unhashed (&x->state_cache_input)) {hlist_add_head_rcu (&x->state_cache_input, state_cache_input); }else {hlist_del_rcu (&x->state_cache_input);hlist_add_head_rcu (&x->state_cache_input, state_cache_input); } -spin_unlock_bh (&net->xfrm.xfrm_state_lock); +spin_unlock (&net->xfrm.xfrm_state_lock); } out: -rcu_read_unlock ();return x; }EXPORT_SYMBOL (xfrm_input_state_lookup);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 564/1276 xfrm: annotate data-races around xfrm_policy_count[] and xfrm_policy_default[]
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 68de007d5ac9df0e3f4f187a179c5c842bb5a2be ]
KCSAN reported a data race involving net->xfrm.policy_count access.
Add missing READ_ONCE()/WRITE_ONCE() annotations on xfrm_policy_count and xfrm_policy_default.
--- include/net/xfrm.h | 8 ++++---- net/xfrm/xfrm_policy.c | 24 ++++++++++++------------ net/xfrm/xfrm_user.c | 18 +++++++++--------- 3 files changed, 25 insertions(+), 25 deletions(-)
include/net/xfrm.h +4 -4
@@ -1185,8 +1185,8 @@ int __xfrm_policy_check(struct sock *, int dir, struct sk_buff *skb,static inline bool __xfrm_check_nopolicy (struct net *net,struct sk_buff *skb,int dir) { -if (!net->xfrm.policy_count[dir] && !secpath_exists (skb)) -return net->xfrm.policy_default[dir] ==XFRM_USERPOLICY_ACCEPT ; +if (!READ_ONCE (net->xfrm.policy_count[dir]) && !secpath_exists (skb)) +return READ_ONCE (net->xfrm.policy_default[dir]) ==XFRM_USERPOLICY_ACCEPT ;return false; }
@@ -1286,8 +1286,8 @@ static inline int xfrm_route_forward(struct sk_buff *skb, unsigned short family) {struct net *net =dev_net (skb->dev); -if (!net->xfrm.policy_count[XFRM_POLICY_OUT ] && - net->xfrm.policy_default[XFRM_POLICY_OUT ] ==XFRM_USERPOLICY_ACCEPT ) +if (!READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_OUT ]) && +READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ]) ==XFRM_USERPOLICY_ACCEPT )return true; return (skb_dst(skb)->flags & DST_NOXFRM) ||
net/xfrm/xfrm_policy.c +12 -12
@@ -685,7 +685,7 @@ static void xfrm_byidx_resize(struct net *net)static inline int xfrm_bydst_should_resize (struct net *net,int dir,int *total) { -unsigned int cnt = net->xfrm.policy_count[dir]; +unsigned int cnt =READ_ONCE (net->xfrm.policy_count[dir]);unsigned int hmask = net->xfrm.policy_bydst[dir].hmask;if (total)
@@ -711,12 +711,12 @@ static inline int xfrm_byidx_should_resize(struct net *net, int total)void xfrm_spd_getinfo (struct net *net,struct xfrmk_spdinfo *si) { - si->incnt = net->xfrm.policy_count[XFRM_POLICY_IN ]; - si->outcnt = net->xfrm.policy_count[XFRM_POLICY_OUT ]; - si->fwdcnt = net->xfrm.policy_count[XFRM_POLICY_FWD ]; - si->inscnt = net->xfrm.policy_count[XFRM_POLICY_IN +XFRM_POLICY_MAX ]; - si->outscnt = net->xfrm.policy_count[XFRM_POLICY_OUT +XFRM_POLICY_MAX ]; - si->fwdscnt = net->xfrm.policy_count[XFRM_POLICY_FWD +XFRM_POLICY_MAX ]; + si->incnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_IN ]); + si->outcnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_OUT ]); + si->fwdcnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_FWD ]); + si->inscnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_IN +XFRM_POLICY_MAX ]); + si->outscnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_OUT +XFRM_POLICY_MAX ]); + si->fwdscnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_FWD +XFRM_POLICY_MAX ]); si->spdhcnt = net->xfrm.policy_idx_hmask; si->spdhmcnt = xfrm_policy_hashmax; }
@@ -2318,7 +2318,7 @@ static void __xfrm_policy_link(struct xfrm_policy *pol, int dir) }list_add (&pol->walk.all, &net->xfrm.policy_all); - net->xfrm.policy_count[dir]++; +WRITE_ONCE (net->xfrm.policy_count[dir], net->xfrm.policy_count[dir] +1 );xfrm_pol_hold (pol); }
@@ -2337,7 +2337,7 @@ static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol, }list_del_init (&pol->walk.all); - net->xfrm.policy_count[dir]--; +WRITE_ONCE (net->xfrm.policy_count[dir], net->xfrm.policy_count[dir] -1 );return pol; }
@@ -3217,7 +3217,7 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net,/* To accelerate a bit... */ if (!if_id && ((dst_orig->flags &DST_NOXFRM ) || - !net->xfrm.policy_count[XFRM_POLICY_OUT ])) + !READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_OUT ]))) goto nopol; xdst =xfrm_bundle_lookup (net, fl, family, dir, &xflo, if_id);
@@ -3290,7 +3290,7 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net, nopol:if ((!dst_orig->dev || !(dst_orig->dev->flags &IFF_LOOPBACK )) && - net->xfrm.policy_default[dir] ==XFRM_USERPOLICY_BLOCK ) { +READ_ONCE (net->xfrm.policy_default[dir]) ==XFRM_USERPOLICY_BLOCK ) { err = -EPERM ; goto error; }
@@ -3744,7 +3744,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,const bool is_crypto_offload = sp && (xfrm_input_state (skb)->xso.type ==XFRM_DEV_OFFLOAD_CRYPTO ); -if (net->xfrm.policy_default[dir] ==XFRM_USERPOLICY_BLOCK ) { +if (READ_ONCE (net->xfrm.policy_default[dir]) ==XFRM_USERPOLICY_BLOCK ) {XFRM_INC_STATS (net,LINUX_MIB_XFRMINNOPOLS );return 0 ; }
net/xfrm/xfrm_user.c +9 -9
@@ -2409,9 +2409,9 @@ static int xfrm_notify_userpolicy(struct net *net) } up =nlmsg_data (nlh); - up->in = net->xfrm.policy_default[XFRM_POLICY_IN ]; - up->fwd = net->xfrm.policy_default[XFRM_POLICY_FWD ]; - up->out = net->xfrm.policy_default[XFRM_POLICY_OUT ]; + up->in =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_IN ]); + up->fwd =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_FWD ]); + up->out =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ]);nlmsg_end (skb, nlh);
@@ -2435,13 +2435,13 @@ static int xfrm_set_default(struct sk_buff *skb, struct nlmsghdr *nlh,struct xfrm_userpolicy_default *up =nlmsg_data (nlh);if (xfrm_userpolicy_is_valid (up->in)) - net->xfrm.policy_default[XFRM_POLICY_IN ] = up->in; +WRITE_ONCE (net->xfrm.policy_default[XFRM_POLICY_IN ], up->in);if (xfrm_userpolicy_is_valid (up->fwd)) - net->xfrm.policy_default[XFRM_POLICY_FWD ] = up->fwd; +WRITE_ONCE (net->xfrm.policy_default[XFRM_POLICY_FWD ], up->fwd);if (xfrm_userpolicy_is_valid (up->out)) - net->xfrm.policy_default[XFRM_POLICY_OUT ] = up->out; +WRITE_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ], up->out);rt_genid_bump_all (net);
@@ -2471,9 +2471,9 @@ static int xfrm_get_default(struct sk_buff *skb, struct nlmsghdr *nlh, } r_up =nlmsg_data (r_nlh); - r_up->in = net->xfrm.policy_default[XFRM_POLICY_IN ]; - r_up->fwd = net->xfrm.policy_default[XFRM_POLICY_FWD ]; - r_up->out = net->xfrm.policy_default[XFRM_POLICY_OUT ]; + r_up->in =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_IN ]); + r_up->fwd =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_FWD ]); + r_up->out =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ]);nlmsg_end (r_skb, r_nlh);return nlmsg_unicast (net->xfrm.nlsk, r_skb, portid);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 565/1276 xfrm: validate selector family and prefixlen during match
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 40f0b1047918539f0b0f795ac65e35336b4c2c78 ]
syzbot reported a shift-out-of-bounds in xfrm_selector_match() due to AF_UNSPEC selector with large prefixlen (e.g. 128) matched against IPv4 flow (when XFRM_STATE_AF_UNSPEC is set).
Fix this by:
- Rejecting mismatched families in xfrm_selector_match.
- Returning false in addr4_match if prefixlen > 32.
- Returning false in addr_match if prefixlen > 128 (prevents overflow).
--- include/net/xfrm.h | 7 +++++++ net/xfrm/xfrm_policy.c | 3 +++ 2 files changed, 10 insertions(+)
include/net/xfrm.h +7 -0
@@ -878,6 +878,9 @@ static inline bool addr_match(const void *token1, const void *token2,unsigned int pdw;unsigned int pbi; +if (prefixlen >128 ) +return false; + pdw = prefixlen >>5 ;/* num of whole u32 in prefix */ pbi = prefixlen &0x1f ;/* num of bits in incomplete u32 in prefix */
@@ -902,6 +905,10 @@ static inline bool addr4_match(__be32 a1, __be32 a2, u8 prefixlen)/* C99 6.5.7 (3): u32 << 32 is undefined behaviour */ if (sizeof (long ) ==4 && prefixlen ==0 )return true; + +if (prefixlen >32 ) +return false; +return !((a1 ^ a2) &htonl (~0UL << (32 - prefixlen))); }
net/xfrm/xfrm_policy.c +3 -0
@@ -242,6 +242,9 @@ __xfrm6_selector_match(const struct xfrm_selector *sel, const struct flowi *fl)bool xfrm_selector_match (const struct xfrm_selector *sel,const struct flowi *fl,unsigned short family) { +if (family != sel->family && sel->family !=AF_UNSPEC ) +return false; +switch (family) {case AF_INET :return __xfrm4_selector_match (sel, fl);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 566/1276 perf machine: Use snprintf() for guestmount path construction
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit fe63d3bca288c5bb983304efd5fc3a5ff3183403 ]
machines__findnew() and machines__create_guest_kernel_maps() use sprintf() to build paths by prepending symbol_conf.guestmount. Both write into PATH_MAX stack buffers, but guestmount comes from user configuration and is not length-checked. A guestmount path at or near PATH_MAX causes a stack buffer overflow.
Switch to snprintf() with sizeof() to prevent overflow. The subsequent access()/fopen() calls will fail on a truncated path.
--- tools/perf/util/machine.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/machine.c +4 -4
@@ -289,7 +289,7 @@ struct machine *machines__findnew(struct machines *machines, pid_t pid)if ((pid !=HOST_KERNEL_ID ) && (pid !=DEFAULT_GUEST_KERNEL_ID ) && (symbol_conf.guestmount)) { -sprintf (path,"%s/%d" , symbol_conf.guestmount, pid); +snprintf (path,sizeof (path),"%s/%d" , symbol_conf.guestmount, pid);if (access (path,R_OK )) {static struct strlist *seen;
@@ -1214,9 +1214,9 @@ int machines__create_guest_kernel_maps(struct machines *machines) namelist[i]->d_name);continue ; } -sprintf (path,"%s/%s/proc/kallsyms" , - symbol_conf.guestmount, - namelist[i]->d_name); +snprintf (path,sizeof (path),"%s/%s/proc/kallsyms" , + symbol_conf.guestmount, + namelist[i]->d_name); ret =access (path,R_OK );if (ret) {pr_debug ("Can't access file %s\n" , path);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 567/1276 perf cs-etm: Validate num_cpu before metadata allocation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 312d91329b8fc6989a916a3f9a12d0674167b7e4 ]
cs_etm__process_auxtrace_info_full() reads num_cpu from untrusted perf.data and uses it to allocate the metadata pointer array:
metadata = zalloc(sizeof(*metadata) * num_cpu);
On 32-bit, sizeof(*metadata) is 4, so num_cpu = 0x40000000 overflows the multiplication to 0, causing zalloc(0) to return a valid zero-sized allocation followed by out-of-bounds writes in the population loop.
Fix by computing priv_size early and using it to bound num_cpu: each CPU needs at least one u64 metadata entry, so num_cpu cannot exceed the total number of u64 entries in the event's private data area.
--- tools/perf/util/cs-etm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
tools/perf/util/cs-etm.c +12 -0
@@ -3428,6 +3428,18 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,/* First the global part */ ptr = (u64 *) auxtrace_info->priv; num_cpu = ptr[CS_PMU_TYPE_CPUS ] &0xffffffff ; + +/* +* Bound num_cpu by the event size: the global header consumes +* CS_ETM_HEADER_SIZE bytes, and each CPU needs at least one u64 +* metadata entry after that. +*/ + priv_size = total_size - event_header_size -INFO_HEADER_SIZE - +CS_ETM_HEADER_SIZE ; +if (num_cpu <=0 || priv_size <=0 || + num_cpu > priv_size / (int )sizeof (u64)) +return -EINVAL ; + metadata =zalloc (sizeof (*metadata) * num_cpu);if (!metadata)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 568/1276 perf cs-etm: Require full global header in auxtrace_info size check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 78d8ba680126f3545e8d0fba667e12d79fd4353b ]
cs_etm__process_auxtrace_info() checks that header.size covers event_header_size + INFO_HEADER_SIZE (16 bytes total), but then accesses ptr[CS_PMU_TYPE_CPUS] at offset 24 from the start of the event. A crafted 16-byte auxtrace_info event passes the size check but reads out-of-bounds.
Include CS_ETM_HEADER_SIZE in the minimum size check so that the global header entries (version, pmu_type_cpus, snapshot) are guaranteed to fit within the event.
--- tools/perf/util/cs-etm-base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/cs-etm-base.c +3 -1
@@ -170,7 +170,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event,u64 *ptr =NULL ;u64 hdr_version; -if (auxtrace_info->header.size < (event_header_size +INFO_HEADER_SIZE )) +/* Ensure priv[] is large enough for the global header entries */ +if (auxtrace_info->header.size < (event_header_size +INFO_HEADER_SIZE + +CS_ETM_HEADER_SIZE ))return -EINVAL ;/* First the global part */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 569/1276 perf cs-etm: Bounds-check CPU in cs_etm__get_queue()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 9a989e60cc6e29d98aed2087425cba53bf4b392d ]
cs_etm__get_queue() indexes etm->queues.queue_array[cpu] without validating that cpu is within nr_queues. When processing AUX_OUTPUT_HW_ID events, the cpu value comes from untrusted perf.data trace payload and flows through cs_etm__process_trace_id_v0_1() and cs_etm__queue_aux_fragment() without bounds checking, allowing an out-of-bounds read with a crafted file.
Add a bounds check in cs_etm__get_queue() and NULL checks in all callers.
Also add NULL checks for queue_array[i].priv in the queue iteration loops in cs_etm__map_trace_id_v0() and cs_etm__process_trace_id_v0_1() — after auxtrace_queues__grow() new entries are zero-initialized so .priv can be NULL. Add a get_cpu_data() NULL check in cs_etm__process_trace_id_v0_1(), matching the existing check in cs_etm__process_trace_id_v0().
--- tools/perf/util/cs-etm.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
tools/perf/util/cs-etm.c +23 -2
@@ -292,8 +292,11 @@ static struct cs_etm_queue *cs_etm__get_queue(struct cs_etm_auxtrace *etm, int c {if (etm->per_thread_decoding)return etm->queues.queue_array[0 ].priv; -else -return etm->queues.queue_array[cpu].priv; + +if (cpu <0 || cpu >= (int )etm->queues.nr_queues) +return NULL ; + +return etm->queues.queue_array[cpu].priv; } static int cs_etm__map_trace_id_v0(struct cs_etm_auxtrace *etm, u8 trace_chan_id,
@@ -306,6 +309,9 @@ static int cs_etm__map_trace_id_v0(struct cs_etm_auxtrace *etm, u8 trace_chan_id* queue associated with that CPU so only one decoder is made. */ etmq =cs_etm__get_queue (etm, cpu_metadata[CS_ETM_CPU ]); +if (!etmq) +return -EINVAL ; +if (etmq->format ==UNFORMATTED )return cs_etm__insert_trace_id_node (etmq, trace_chan_id, cpu_metadata);
@@ -318,6 +324,9 @@ static int cs_etm__map_trace_id_v0(struct cs_etm_auxtrace *etm, u8 trace_chan_idint ret; etmq = etm->queues.queue_array[i].priv; +if (!etmq) +continue ; + ret =cs_etm__insert_trace_id_node (etmq, trace_chan_id, cpu_metadata);if (ret)
@@ -358,6 +367,9 @@ static int cs_etm__process_trace_id_v0_1(struct cs_etm_auxtrace *etm, int cpu,u32 sink_id =FIELD_GET (CS_AUX_HW_ID_SINK_ID_MASK , hw_id);u8 trace_id =FIELD_GET (CS_AUX_HW_ID_TRACE_ID_MASK , hw_id); +if (!etmq) +return -EINVAL ; +/* * Check sink id hasn't changed in per-cpu mode. In per-thread mode, * let it pass for now until an actual overlapping trace ID is hit. In
@@ -375,6 +387,9 @@ static int cs_etm__process_trace_id_v0_1(struct cs_etm_auxtrace *etm, int cpu,for (unsigned int i =0 ; i < etm->queues.nr_queues; ++i) {struct cs_etm_queue *other_etmq = etm->queues.queue_array[i].priv; +if (!other_etmq) +continue ; +/* Different sinks, skip */ if (other_etmq->sink_id != etmq->sink_id)continue ;
@@ -396,6 +411,9 @@ static int cs_etm__process_trace_id_v0_1(struct cs_etm_auxtrace *etm, int cpu, } cpu_data =get_cpu_data (etm, cpu); +if (!cpu_data) +return -EINVAL ; + ret =cs_etm__insert_trace_id_node (etmq, trace_id, cpu_data);if (ret)return ret;
@@ -3146,6 +3164,9 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o aux_offset + aux_size <= auxtrace_event->offset + auxtrace_event->size) {struct cs_etm_queue *etmq = etm->queues.queue_array[auxtrace_event->idx].priv; +if (!etmq) +return -EINVAL ; +/* * If this AUX event was inside this buffer somewhere, create a new auxtrace event * based on the sizes of the aux event, and queue that fragment.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 570/1276 ASoC: tlv320aic3x: restrict CLKDIV bypass Q values in dual-rate mode
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sen Wang <[email protected]>
[ Upstream commit fdf043f5f3bae150b678feae3d7bb1beed87ec14 ]
The datasheet documents that when the PLL is disabled and dual-rate mode is enabled, only Q values {4, 8, 9, 12, 16} are valid for the CLKDIV bypass path; all other Q values produce invalid bitclock output.
The existing loop iterates Q from 2 to 17 without this restriction, causing silent audio failure when an out-of-spec Q is picked.
Restrict the Q search to the allowed set in dual-rate mode.
--- sound/soc/codecs/tlv320aic3x.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
sound/soc/codecs/tlv320aic3x.c +19 -6
@@ -1049,11 +1049,13 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { + static const u8 dual_rate_q[] = {4, 8, 9, 12, 16};struct snd_soc_component *component = dai->component;struct aic3x_priv *aic3x =snd_soc_component_get_drvdata (component);int codec_clk =0 , bypass_pll =0 , fsref, last_clk =0 ;u8 data, j, r, p, pll_q, pll_p =1 , pll_r =1 , pll_j =1 ;u16 d, pll_d =1 ; +bool dual_rate;int clk;int width = aic3x->slot_width;
@@ -1079,14 +1081,25 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,/* Fsref can be 44100 or 48000 */ fsref = (params_rate (params) %11025 ==0 ) ?44100 :48000 ; + dual_rate =params_rate (params) >=64000 ;/* Try to find a value for Q which allows us to bypass the PLL and * generate CODEC_CLK directly. */ -for (pll_q =2 ; pll_q <18 ; pll_q++) -if (aic3x->sysclk / (128 * pll_q) == fsref) { - bypass_pll =1 ; -break ; +if (dual_rate) { +for (int i =0 ; i <ARRAY_SIZE (dual_rate_q); i++) { + pll_q = dual_rate_q[i]; +if (aic3x->sysclk / (128 * pll_q) == fsref) { + bypass_pll =1 ; +break ; + } } + }else { +for (pll_q =2 ; pll_q <18 ; pll_q++) +if (aic3x->sysclk / (128 * pll_q) == fsref) { + bypass_pll =1 ; +break ; + } + }if (bypass_pll) { pll_q &=0xf ;
@@ -1106,13 +1119,13 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,* right DAC to right channel input */ data = (LDAC2LCH |RDAC2RCH ); data |= (fsref ==44100 ) ?FSREF_44100 :FSREF_48000 ; -if (params_rate (params) >=64000 ) +if (dual_rate) data |=DUAL_RATE_MODE ;snd_soc_component_write (component,AIC3X_CODEC_DATAPATH_REG , data);/* codec sample rate select */ data = (fsref *20 ) /params_rate (params); -if (params_rate (params) <64000 ) +if (!dual_rate) data /=2 ; data /=5 ; data -=2 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 571/1276 drm/amdkfd: Avoid double-unpin of DOORBELL/MMIO BOs on free
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunxiang Li <[email protected]>
[ Upstream commit 3f0cc1735273a57c5116710cf0202e12152f59cc ]
amdgpu_amdkfd_gpuvm_free_memory_of_gpu() unpinned DOORBELL and MMIO remap BOs (which are pinned at allocation time) before checking whether the BO is still mapped to the GPU. When the BO is still mapped, the function returns -EBUSY and leaves the BO alive, but it has already been unpinned. The BO is then unpinned again when it is finally freed during process teardown, triggering a ttm_bo_unpin() underflow warning:
WARNING: CPU: 18 PID: 15066 at ttm/ttm_bo.c:650 amdttm_bo_unpin+0x6d/0x80 [amdttm] Workqueue: kfd_process_wq kfd_process_wq_release [amdgpu] RIP: 0010:amdttm_bo_unpin+0x6d/0x80 [amdttm] Call Trace: amdgpu_bo_unpin+0x1a/0x90 [amdgpu] amdgpu_amdkfd_gpuvm_unpin_bo+0x31/0xb0 [amdgpu] amdgpu_amdkfd_gpuvm_free_memory_of_gpu+0x3bf/0x460 [amdgpu] kfd_process_free_outstanding_kfd_bos+0xd4/0x170 [amdgpu] kfd_process_wq_release+0x109/0x1b0 [amdgpu] process_one_work+0x1e2/0x3b0 worker_thread+0x50/0x3a0 kthread+0xdd/0x100 ret_from_fork+0x29/0x50
Move the unpin after the mapped_to_gpu_memory check so it only happens once we are committed to freeing the BO.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9 -7
@@ -1916,13 +1916,6 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(mutex_lock (&mem->lock); -/* Unpin MMIO/DOORBELL BO's that were pinned during allocation */ -if (mem->alloc_flags & - (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | -KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { -amdgpu_amdkfd_gpuvm_unpin_bo (mem->bo); - } - mapped_to_gpu_memory = mem->mapped_to_gpu_memory; is_imported = mem->is_imported;mutex_unlock (&mem->lock);
@@ -1936,6 +1929,15 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(return -EBUSY ; } +/* At this point the BO is guaranteed to be freed, so unpin the +* MMIO/DOORBELL BOs that were pinned during allocation. +*/ +if (mem->alloc_flags & + (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { +amdgpu_amdkfd_gpuvm_unpin_bo (mem->bo); + } +/* Make sure restore workers don't access the BO any more */ mutex_lock (&process_info->lock);list_del (&mem->validate_list);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 572/1276 drm/amdkfd: fix list_del corruption in kfd_criu_resume_svm
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
[ Upstream commit 8fa5655da368d0306c03e9dc9cda8ae2a7840926 ]
The cleanup tail of kfd_criu_resume_svm() walks svms->criu_svm_metadata_list and kfree()s each struct criu_svm_metadata without removing it from the list. The list head is left pointing at freed kmalloc-96 objects.
A second AMDKFD_IOC_CRIU_OP from the same process re-enters: list_empty() reads the dangling ->next (use-after-free), the loop walks freed entries, and each is kfree()'d again (double-free). This is reachable by an unprivileged render-group user via /dev/kfd with no capabilities required.
Add list_del() before the kfree() so the list is properly emptied. The list_for_each_entry_safe() iterator already caches the next pointer, so unlinking during the walk is safe.
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -0
@@ -4051,6 +4051,7 @@ int kfd_criu_resume_svm(struct kfd_process *p)list_for_each_entry_safe (criu_svm_md, next, &svms->criu_svm_metadata_list, list) {pr_debug ("freeing criu_svm_md[]\n\tstart: 0x%llx\n" , criu_svm_md->data.start_addr); +list_del (&criu_svm_md->list);kfree (criu_svm_md); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 573/1276 drm/amdgpu: initialize irq.lock spinlock earlier
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thadeu Lima de Souza Cascardo <[email protected]>
[ Upstream commit a2b270c0ecf6d95bcd14ef4c20d0301a88143ff5 ]
If there is an early failure during amdgpu probe, like missing firmware, it will end up calling amdgpu_irq_disable_all, which takes irq.lock spinlock without it being initialized.
Initializing irq.lock earlier at amdgpu_device_init fixes the issue.
[ 79.334079] INFO: trying to register non-static key. [ 79.334081] The code is fine but needs lockdep annotation, or maybe [ 79.334083] you didn't initialize this object before use? [ 79.334084] turning off the locking correctness validator. [ 79.334088] CPU: 2 UID: 0 PID: 1819 Comm: bash Not tainted 7.1.0-rc5-gfd06300b2348 #96 PREEMPT 8e8f461221633dae3c832d6689eaf0546c0ed4cd [ 79.334092] Hardware name: Valve Jupiter/Jupiter, BIOS F7A0133 08/05/2024 [ 79.334094] Call Trace: [ 79.334095] <TASK> [ 79.334097] dump_stack_lvl+0x5d/0x80 [ 79.334103] register_lock_class+0x7af/0x7c0 [ 79.334109] __lock_acquire+0x416/0x2610 [ 79.334114] lock_acquire+0xcf/0x310 [ 79.334117] ? amdgpu_irq_disable_all+0x3b/0xf0 [amdgpu c88bab43d391d519ad0d5c8e5a099b4aceefa180] [ 79.334503] ? _raw_spin_lock_irqsave+0x53/0x60 [ 79.334508] _raw_spin_lock_irqsave+0x3f/0x60 [ 79.334510] ? amdgpu_irq_disable_all+0x3b/0xf0 [amdgpu c88bab43d391d519ad0d5c8e5a099b4aceefa180] [ 79.334881] amdgpu_irq_disable_all+0x3b/0xf0 [amdgpu c88bab43d391d519ad0d5c8e5a099b4aceefa180] [ 79.335240] amdgpu_device_fini_hw+0x90/0x32c [amdgpu c88bab43d391d519ad0d5c8e5a099b4aceefa180] [ 79.335704] amdgpu_driver_load_kms.cold+0x22/0x44 [amdgpu c88bab43d391d519ad0d5c8e5a099b4aceefa180] [ 79.336159] amdgpu_pci_probe+0x204/0x440 [amdgpu c88bab43d391d519ad0d5c8e5a099b4aceefa180] [ 79.336494] local_pci_probe+0x3c/0x80 [ 79.336500] pci_call_probe+0x55/0x2e0 [ 79.336505] ? _raw_spin_unlock+0x2d/0x50 [ 79.336508] ? pci_match_device+0x157/0x180 [ 79.336512] pci_device_probe+0x9b/0x170 [ 79.336516] really_probe+0xd5/0x370 [ 79.336521] __driver_probe_device+0x84/0x150 [ 79.336525] device_driver_attach+0x47/0xb0 [ 79.336528] bind_store+0x73/0xc0 [ 79.336531] kernfs_fop_write_iter+0x176/0x250 [ 79.336536] vfs_write+0x24d/0x560 [ 79.336542] ksys_write+0x71/0xe0 [ 79.336546] do_syscall_64+0x122/0x710 [ 79.336550] ? do_syscall_64+0xd1/0x710 [ 79.336553] entry_SYSCALL_64_after_hwframe+0x4b/0x53 [ 79.336557] RIP: 0033:0x7f92fd675006 [ 79.336561] Code: 5d e8 41 8b 93 08 03 00 00 59 5e 48 83 f8 fc 75 19 83 e2 39 83 fa 08 75 11 e8 26 ff ff ff 66 0f 1f 44 00 00 48 8b 45 10 0f 05 <48> 8b 5d f8 c9 c3 0f 1f 40 00 f3 0f 1e fa 55 48 89 e5 48 83 ec 08 [ 79.336562] RSP: 002b:00007ffe4fa867a0 EFLAGS: 00000202 ORIG_RAX: 0000000000000001 [ 79.336565] RAX: ffffffffffffffda RBX: 000000000000000d RCX: 00007f92fd675006 [ 79.336567] RDX: 000000000000000d RSI: 000055b2dfce59b0 RDI: 0000000000000001 [ 79.336568] RBP: 00007ffe4fa867c0 R08: 0000000000000000 R09: 0000000000000000 [ 79.336569] R10: 0000000000000000 R11: 0000000000000202 R12: 000000000000000d [ 79.336570] R13: 000055b2dfce59b0 R14: 00007f92fd7ca5c0 R15: 000055b2dfdbaf70 [ 79.336574] </TASK>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
@@ -4201,6 +4201,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->enforce_isolation_mutex);mutex_init (&adev->gfx.kfd_sch_mutex); +spin_lock_init (&adev->irq.lock); +amdgpu_device_init_apu_flags (adev); r =amdgpu_device_check_arguments (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -2
@@ -273,8 +273,6 @@ int amdgpu_irq_init(struct amdgpu_device *adev)unsigned int irq, flags;int r; -spin_lock_init (&adev->irq.lock); -/* Enable MSI if not disabled by module parameter */ adev->irq.msi_enabled = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 574/1276 octeontx2-pf: Fix leak of SQ timestamp buffer on teardown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ratheesh Kannoth <[email protected]>
[ Upstream commit a056db30de92945ff8ee6033096678bfbae878e3 ]
The send-queue timestamp ring is allocated with qmem_alloc() when timestamping is used, but otx2_free_sq_res() never freed sq->timestamps, leaking that memory across ifdown and device removal. Add the missing qmem_free() alongside the other SQ companion buffers.
--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +1 -0
@@ -1444,6 +1444,7 @@ static void otx2_free_sq_res(struct otx2_nic *pf)continue ;qmem_free (pf->dev, sq->sqe);qmem_free (pf->dev, sq->tso_hdrs); +qmem_free (pf->dev, sq->timestamps);kfree (sq->sg);kfree (sq->sqb_ptrs); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 575/1276 net: psample: fix info leak in PSAMPLE_ATTR_DATA
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit aedd02af1f8b0bceb7f42f5a21c41634ca9ed390 ]
psample open codes nla_put() presumably to avoid wiping the data with 0s just to override it with packet data. This open coding is missing clearing the pad, however, each netlink attr is padded to 4B and data_len may not be divisible by 4B.
--- net/psample/psample.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/psample/psample.c +4 -2
@@ -476,15 +476,17 @@ void psample_sample_packet(struct psample_group *group, goto error;if (data_len) { -int nla_len =nla_total_size (data_len); +int nla_len =nla_attr_size (data_len);struct nlattr *nla; nla =skb_put (nl_skb, nla_len); nla->nla_type =PSAMPLE_ATTR_DATA ; - nla->nla_len =nla_attr_size (data_len); + nla->nla_len = nla_len;if (skb_copy_bits (skb,0 ,nla_data (nla), data_len)) goto error; + +skb_put_zero (nl_skb,nla_padlen (data_len)); }#ifdef CONFIG_INET
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 576/1276 sctp: hold socket lock when dumping endpoints in sctp_diag
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
[ Upstream commit 7d8297e26b4e20b5d1c3c3fe51fe81a1c7fbc823 ]
SCTP_DIAG endpoint dumping was traversing endpoint address lists without holding lock_sock(), while those lists could change concurrently via socket operations (e.g., bindx changes). This creates a race where nla_reserve() counts addresses under RCU protection, but the subsequent copy may see fewer entries, potentially leaking uninitialized memory to userspace.
Fix this by:
- Taking a reference on each endpoint during hash traversal
- Moving socket operations (lock_sock()) outside read_lock_bh()
- Serializing address list access during dump
- Reworking sctp_for_each_endpoint() to support restart-based traversal with (net, pos) tracking
Also:
- Add WARN_ON_ONCE() for inconsistent address counts
- Fix idiag_states filtering for LISTEN vs association cases
- Skip dumping endpoints being freed (ep->base.dead)
- Move dump position tracking into iterator, removing cb->args[4] and its comment for sctp_ep_dump().,
- Update the comment for cb->args[4] and remove the comment for unused cb->args[5] for sctp_sock_dump().
Note: traversal is restart-based and may re-scan buckets multiple times, but this is acceptable due to small bucket sizes and required to support sleeping-safe callbacks.
This issue was reported by Nico Yip (@_cyeaa_) working with TrendAI Zero Day Initiative.
--- include/net/sctp/sctp.h | 3 +- net/sctp/diag.c | 67 ++++++++++++++++++++--------------------- net/sctp/socket.c | 29 +++++++++++++----- 3 files changed, 56 insertions(+), 43 deletions(-)
include/net/sctp/sctp.h +2 -1
@@ -112,7 +112,8 @@ int sctp_transport_lookup_process(sctp_callback_t cb, struct net *net, const union sctp_addr *paddr, void *p, int dif);int sctp_transport_traverse_process (sctp_callback_t cb,sctp_callback_t cb_done,struct net *net,int *pos,void *p); -int sctp_for_each_endpoint (int (*cb)(struct sctp_endpoint *,void *),void *p); +int sctp_for_each_endpoint (int (*cb)(struct sctp_endpoint *,void *), +struct net *net,int *pos,void *p);int sctp_get_sctp_info (struct sock *sk,struct sctp_association *asoc,struct sctp_info *info);
net/sctp/diag.c +32 -35
121 lines not on this page · raw message
net/sctp/socket.c +22 -7
@@ -5323,24 +5323,39 @@ struct sctp_transport *sctp_transport_get_idx(struct net *net, }int sctp_for_each_endpoint (int (*cb)(struct sctp_endpoint *,void *), -void *p) { -int err =0 ; -int hash =0 ; -struct sctp_endpoint *ep; +struct net *net,int *pos,void *p) { +int err, hash =0 , idx =0 , start;struct sctp_hashbucket *head; +struct sctp_endpoint *ep;for (head = sctp_ep_hashtable; hash < sctp_ep_hashsize; hash++, head++) { + start = idx; +again:read_lock_bh (&head->lock);sctp_for_each_hentry (ep, &head->chain) { - err =cb (ep, p); -if (err) +if (sock_net (ep->base.sk) != net) +continue ; +if (idx++ >= *pos) { +sctp_endpoint_hold (ep);break ; + } }read_unlock_bh (&head->lock); + +if (ep) { + err =cb (ep, p); +sctp_endpoint_put (ep); +if (err) +return err; + (*pos)++; + + idx = start; + goto again; + } } -return err; +return 0 ; }EXPORT_SYMBOL_GPL (sctp_for_each_endpoint);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 577/1276 PCI: iproc: Restore .map_irq() for the platform bus driver
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Tomlinson <[email protected]>
[ Upstream commit 3c2e6cc6affa8acdb99a580be1f8f297edf54204 ]
Commit b64aa11eb2dd ("PCI: Set bridge map_irq and swizzle_irq to default functions") moved the assignment of default .map_irq() callback to devm_of_pci_bridge_init() and removed the initialization of 'iproc_pcie::map_irq' in platform bus driver. This led to the callback getting assigned the NULL pointer for platform bus driver, thereby breaking the INTx functionality, since 'iproc_pcie::map_irq' overrides the 'pci_host_bridge::map_irq' callback in iproc_pcie_setup().
This issue only affected the iproc platform bus driver as this driver relies on the default callback for non-PAXC controllers. iproc-brcm driver was already providing the custom mapping function, so it was unaffected.
Restore the original (and intended) behaviour to use the default map_irq function by removing the local 'iproc_pcie::map_irq' pointer and directly assigning the 'pci_host_bridge::map_irq' callback in iproc-bcma driver. This ensures that the default 'map_irq' callback is used for platform bus driver and only iproc-brcm driver overrides it with a custom one.
--- drivers/pci/controller/pcie-iproc-bcma.c | 2 +- drivers/pci/controller/pcie-iproc-platform.c | 2 +- drivers/pci/controller/pcie-iproc.c | 1 - drivers/pci/controller/pcie-iproc.h | 2 -- 4 files changed, 2 insertions(+), 5 deletions(-)
drivers/pci/controller/pcie-iproc-bcma.c +1 -1
@@ -64,7 +64,7 @@ static int iproc_bcma_pcie_probe(struct bcma_device *bdev)if (ret)return ret; - pcie->map_irq = iproc_bcma_pcie_map_irq; + bridge->map_irq = iproc_bcma_pcie_map_irq;bcma_set_drvdata (bdev, pcie);
drivers/pci/controller/pcie-iproc-platform.c +1 -1
@@ -98,7 +98,7 @@ static int iproc_pltfm_pcie_probe(struct platform_device *pdev)switch (pcie->type) {case IPROC_PCIE_PAXC :case IPROC_PCIE_PAXC_V2 : - pcie->map_irq =NULL ; + bridge->map_irq =NULL ;break ;default :break ;
drivers/pci/controller/pcie-iproc.c +0 -1
@@ -1514,7 +1514,6 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) host->ops = &iproc_pcie_ops; host->sysdata = pcie; - host->map_irq = pcie->map_irq; ret =pci_host_probe (host);if (ret <0 ) {
drivers/pci/controller/pcie-iproc.h +0 -2
@@ -61,7 +61,6 @@ struct iproc_msi;* @base_addr: PCIe host controller register base physical address * @mem: host bridge memory window resource * @phy: optional PHY device that controls the Serdes -* @map_irq: function callback to map interrupts * @ep_is_internal: indicates an internal emulated endpoint device is connected * @iproc_cfg_read: indicates the iProc config read function should be used * @rej_unconfig_pf: indicates the root complex needs to detect and reject
@@ -91,7 +90,6 @@ struct iproc_pcie {phys_addr_t base_addr;struct resource mem;struct phy *phy; -int (*map_irq)(const struct pci_dev *,u8 ,u8 );bool ep_is_internal;bool iproc_cfg_read;bool rej_unconfig_pf;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 578/1276 spi: rpc-if: Use correct device for hardware reinitialization on resume
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Quang Nguyen <[email protected]>
[ Upstream commit 7b25dbafa2fce50b1a48c1d057adb35da3563f9b ]
rpcif_spi_resume() currently passes the SPI controller device to rpcif_hw_init(), but the function should be called with the RPC interface device.
Retrieve the rpcif private data from the SPI controller and pass rpc->dev instead. Also propagate the return value of rpcif_hw_init() so that a failure during resume is properly reported rather than silently ignored.
--- drivers/spi/spi-rpc-if.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/spi/spi-rpc-if.c +5 -1
@@ -192,8 +192,12 @@ static int __maybe_unused rpcif_spi_suspend(struct device *dev)static int __maybe_unused rpcif_spi_resume (struct device *dev) {struct spi_controller *ctlr =dev_get_drvdata (dev); +struct rpcif *rpc =spi_controller_get_devdata (ctlr); +int ret; -rpcif_hw_init (dev, false); + ret =rpcif_hw_init (rpc->dev, false); +if (ret) +return ret;return spi_controller_resume (ctlr); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 579/1276 virtio-net: fix len check in receive_big()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 9e5ad06ea826322ce8c58b4a68442a96f600c3c4 ]
receive_big() bounds the device-announced length by (big_packets_num_skbfrags + 1) * PAGE_SIZE. That is still too loose:add_recvbuf_big() sets sg[1] to start at offset sizeof(struct padded_vnet_hdr) into the first page, so the chain actually carries hdr_len + (PAGE_SIZE - sizeof(padded_vnet_hdr)) + big_packets_num_skbfrags * PAGE_SIZE bytes -- 20 bytes less than the check allows for the common hdr_len == 12 case.
A malicious virtio backend can announce a len in that gap. page_to_skb() then walks one frag past the page chain, storing a NULL page->private into skb_shinfo()->frags[MAX_SKB_FRAGS], which is both an out-of-bounds write past the static frag array and a NULL frag handed up the rx path.
Bound len by the size add_recvbuf_big() actually advertised.
--- drivers/net/virtio_net.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +6 -3
@@ -1895,15 +1895,18 @@ static struct sk_buff *receive_big(struct net_device *dev, struct virtnet_rq_stats *stats) {struct page *page = buf; +unsigned long max_len;struct sk_buff *skb; + max_len = (vi->big_packets_num_skbfrags +1 ) *PAGE_SIZE - +sizeof (struct padded_vnet_hdr ) + vi->hdr_len; +/* Make sure that len does not exceed the size allocated in * add_recvbuf_big. */ -if (unlikely (len > (vi->big_packets_num_skbfrags +1 ) *PAGE_SIZE )) { +if (unlikely (len > max_len)) {pr_debug ("%s: rx error: len %u exceeds allocated size %lu\n" , - dev->name, len, - (vi->big_packets_num_skbfrags +1 ) *PAGE_SIZE ); + dev->name, len, max_len); goto err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 580/1276 dpaa2-switch: fix VLAN upper check not rejecting bridge join
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ioana Ciornei <[email protected]>
[ Upstream commit ed2294f94e34e97342850c40b320833d881c3819 ]
The blamed commit refactored the prechangeupper event handling but failed to actually return an error in case dpaa2_switch_prevent_bridging_with_8021q_upper() detected a 802.1q upper on a port which tries to join a bridge. Fix this by returning err instead of 0.
--- drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +1 -1
@@ -2176,7 +2176,7 @@ dpaa2_switch_prechangeupper_sanity_checks(struct net_device *netdev,if (err) {NL_SET_ERR_MSG_MOD (extack,"Cannot join a bridge while VLAN uppers are present" ); -return 0 ; +return err; }netdev_for_each_lower_dev (upper_dev, other_dev, iter) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 581/1276 devlink: Fix parent ref leak in devl_rate_node_create()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit ba45106342bbdd905651cb9fcefb8c11871d4c25 ]
In the original commit the function bails out on kstrdup failure, forgetting to decrement the refcnt of the parent.
Fix that by moving the parent refcnt setting after kstrdup.
--- net/devlink/rate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/devlink/rate.c +5 -5
@@ -597,11 +597,6 @@ devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,if (!rate_node)return ERR_PTR (-ENOMEM ); -if (parent) { - rate_node->parent = parent; -refcount_inc (&rate_node->parent->refcnt); - } - rate_node->type =DEVLINK_RATE_TYPE_NODE ; rate_node->devlink = devlink; rate_node->priv = priv;
@@ -612,6 +607,11 @@ devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,return ERR_PTR (-ENOMEM ); } +if (parent) { + rate_node->parent = parent; +refcount_inc (&rate_node->parent->refcnt); + } +refcount_set (&rate_node->refcnt,1 );list_add (&rate_node->list, &devlink->rate_list);devlink_rate_notify (rate_node,DEVLINK_CMD_RATE_NEW );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 582/1276 flow_dissector: check device type before reading ETH_ADDRS
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yun Zhou <[email protected]>
[ Upstream commit bf6e8af2c8be77489bedeae9f8a9654cb710e500 ]
__skb_flow_dissect() unconditionally reads 12 bytes from eth_hdr(skb) when FLOW_DISSECTOR_KEY_ETH_ADDRS is requested. This assumes the skb has a valid Ethernet header at mac_header, which is not always the case.
The problem can be triggered by:
1. Creating a TUN device in L3 mode (IFF_TUN, hard_header_len=0)
2. Attaching a multiq qdisc with a flower filter matching on eth_src
3. Sending a packet through AF_PACKET
Since TUN in L3 mode has no link-layer header, mac_header points to the L3 data area. The flow dissector reads 12 bytes of uninitialized skb memory, which then propagates through fl_set_masked_key() and is used as a rhashtable lookup key in __fl_lookup(), as reported by KMSAN.
Rejecting the filter in the control path (at tc filter add time) is not feasible because TC filter blocks can be shared between arbitrary devices -- a filter installed on an Ethernet device may later classify packets on a headerless device through a shared block. The device association is not fixed at filter creation time.
Fix this by gating the memcpy on dev->type == ARPHRD_ETHER, which ensures only true Ethernet-framed packets have their addresses read. This is more precise than the previous hard_header_len >= 12 check, which would incorrectly pass for non-Ethernet link types like IPoIB (ARPHRD_INFINIBAND, hard_header_len=24) and FDDI (hard_header_len=21) whose L2 headers are not in Ethernet format. Additionally check skb_mac_header_was_set() to guard against the pathological case where mac_header is the unset sentinel (~0U), which would cause eth_hdr() to return a wild pointer.
For the act_mirred redirect case (Ethernet packet redirected to a non-Ethernet device sharing a TC block), zeroing the key is the correct
behavior: the packet is now being classified on the target device, where Ethernet address matching is not semantically meaningful.
Note: on non-Ethernet devices, the zeroed key will match a filter configured with all-zero MAC addresses. This is an improvement over the previous behavior where uninitialized memory could randomly match any filter.
--- net/core/flow_dissector.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/core/flow_dissector.c +10 -2
@@ -1173,13 +1173,21 @@ bool __skb_flow_dissect(const struct net *net,if (dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_ETH_ADDRS )) { -struct ethhdr *eth =eth_hdr (skb);struct flow_dissector_key_eth_addrs *key_eth_addrs; key_eth_addrs =skb_flow_dissector_target (flow_dissector,FLOW_DISSECTOR_KEY_ETH_ADDRS , target_container); -memcpy (key_eth_addrs, eth,sizeof (*key_eth_addrs)); +/* TC filter blocks can be shared across devices with +* different link types, so we cannot validate this +* when the filter is installed -- check at dissect time. +*/ +if (skb && skb->dev && + skb->dev->type ==ARPHRD_ETHER && +skb_mac_header_was_set (skb)) +memcpy (key_eth_addrs,eth_hdr (skb),sizeof (*key_eth_addrs)); +else +memset (key_eth_addrs,0 ,sizeof (*key_eth_addrs)); } if (dissector_uses_key(flow_dissector,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 583/1276 ALSA: usb-audio: Kill MIDI 2.0 URBs before freeing endpoints
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit f199c8a8bdd54296d3458777e70fe82a78bd9817 ]
MIDI 2.0 input URBs are started during snd_usb_midi_v2_create(). A later setup failure can still jump to snd_usb_midi_v2_free(), which currently frees each endpoint and its coherent URB buffers without first stopping the submitted URBs. A completion can then dereference the embedded URB context and endpoint state after they have been freed, or try to resubmit from the stale endpoint.
This was observed as a KASAN slab-use-after-free in input_urb_complete().
The buggy scenario involves two paths, with each column showing the order within that path:
probe error path: USB completion path:
1. start_input_streams() submits 1. The HCD still owns a
input URBs. submitted input URB.
2. A later setup helper returns 2. input_urb_complete() runs
an error. with urb->context in ep.
3. snd_usb_midi_v2_free() frees 3. The completion reads ep
endpoint storage and URB buffers. state and can requeue URBs.
Make the endpoint destructor follow the same teardown ordering used for disconnect when the endpoint has not already been disconnected: publish ep->disconnected, kill the URBs synchronously, and drain the endpoint before freeing URB buffers and endpoint storage. The guard avoids repeating the stop sequence after the normal snd_usb_midi_v2_disconnect_all() path, while still synchronizing the direct MIDI 2.0 create-error free path.
Validation reproduced this kernel report:
BUG: KASAN: slab-use-after-free in input_urb_complete+0x37/0x1b0 Workqueue: usb_hub_wq hub_event RIP: 0010:_raw_spin_unlock_irq+0x2e/0x50 Read of size 8 Call trace: dump_stack_lvl+0x77/0xb0 print_report+0xce/0x5f0 input_urb_complete+0x37/0x1b0 (sound/usb/midi2.c:186) srso_alias_return_thunk+0x5/0xfbef5 __virt_addr_valid+0x19f/0x330 kasan_report+0xe0/0x110 __usb_hcd_giveback_urb+0x112/0x1d0 dummy_timer+0xaaa/0x19a0 lock_is_held_type+0x9a/0x110 __lock_acquire+0x467/0x28b0 mark_held_locks+0x40/0x70 _raw_spin_unlock_irqrestore+0x44/0x60 lockdep_hardirqs_on_prepare+0xbb/0x1a0 __hrtimer_run_queues+0x101/0x520 hrtimer_run_softirq+0xd0/0x130 handle_softirqs+0x15b/0x670 __irq_exit_rcu+0xd0/0x170 irq_exit_rcu+0xe/0x20 sysvec_apic_timer_interrupt+0x6c/0x80 asm_sysvec_apic_timer_interrupt+0x1a/0x20
--- sound/usb/midi2.c | 5 +++++ 1 file changed, 5 insertions(+)
sound/usb/midi2.c +5 -0
@@ -478,6 +478,11 @@ static int create_midi2_endpoint(struct snd_usb_midi2_interface *umidi,static void free_midi2_endpoint (struct snd_usb_midi2_endpoint *ep) {list_del (&ep->list); +if (!ep->disconnected) { + ep->disconnected =1 ; +kill_midi_urbs (ep, false); +drain_urb_queue (ep); + }free_midi_urbs (ep);kfree (ep); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 584/1276 arm64/hw_breakpoint: reject unaligned watchpoints that would truncate BAS
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit 4cc70f75853bebac022334b6a86b953348072f74 ]
hw_breakpoint_arch_parse() positions the BAS bit pattern in hw->ctrl.len with
offset = hw->address & alignment_mask; /* 0..7 */ hw->ctrl.len <<= offset;
ctrl.len is an 8-bit bitfield (struct arch_hw_breakpoint_ctrl::len is u32 :8), so the shift silently drops any bits past bit 7. For non-compat AArch64 watchpoints the offset is unbounded relative to ctrl.len: a perf_event_open(PERF_TYPE_BREAKPOINT) caller asking for HW_BREAKPOINT_W with bp_addr=page+1 and bp_len=HW_BREAKPOINT_LEN_8 ends up with 0xff << 1 = 0x1fe, stored as 0xfe. The kernel programs WCR.BAS=0xfe and the hardware watches bytes [1..7] instead of the requested [1..8] -- the eighth byte is silently dropped. The syscall still returns success, leaving userspace to discover the gap by empirical probing.
The same class affects HW_BREAKPOINT_LEN_{2,4} when offset pushes the high BAS bit past bit 7 (e.g. LEN_4 with offset=5 yields 0xe0 instead of 0x1e0). No memory-safety impact -- the value is masked into 8 bits before encoding -- but debuggers and perf users observe missed events on bytes they thought they were watching.
The AArch32 branch immediately above already rejects unrepresentable (offset, len) combinations via an explicit switch. Mirror that for the non-compat branch by checking that the shifted pattern fits in the BAS field, returning -EINVAL when it does not.
GDB and similar debuggers are unaffected by the stricter check. aarch64_linux_set_debug_regs() already treats EINVAL on NT_ARM_HW_WATCH as a downgrade signal: it clears kernel_supports_any_contiguous_range, calls aarch64_downgrade_regs() to round the BAS up to a legacy 0x01/03/0f/ff mask with an aligned base, and retries -- the same fallback path that PR-20207 introduced. The new -EINVAL is therefore reachable only from a raw perf_event_open() that pairs an unaligned base with an oversized bp_len, which is precisely the bug.
Reproducer:
struct perf_event_attr a = {
.type = PERF_TYPE_BREAKPOINT, .size = sizeof(a),
.bp_type = HW_BREAKPOINT_W,
.bp_addr = (uintptr_t)(buf + 1),
.bp_len = HW_BREAKPOINT_LEN_8,
.exclude_kernel = 1, .exclude_hv = 1, };
int fd = perf_event_open(&a, 0, -1, -1, 0);
/* before this fix: succeeds, watches 7 bytes (buf+1..buf+7) */
/* after this fix: fails with EINVAL */
--- arch/arm64/kernel/hw_breakpoint.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm64/kernel/hw_breakpoint.c +9 -0
@@ -559,6 +559,15 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,else alignment_mask =0x7 ; offset = hw->address & alignment_mask; + +/* +* BAS is an 8-bit field in WCR/BCR; the shift below would +* silently drop the high bits of ctrl.len when offset + len +* exceeds 8, programming hardware to watch fewer bytes than +* the user requested. +*/ +if (((u32 )hw->ctrl.len << offset) >ARM_BREAKPOINT_LEN_8 ) +return -EINVAL ; } hw->address &= ~alignment_mask;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 585/1276 thermal: intel: Fix dangling resources on thermal_throttle_online() failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Neri <[email protected]>
[ Upstream commit b91d287fa7a1ba0727eed5823c6ee4924ee5fa31 ]
The function thermal_throttle_add_dev() may fail and abort a CPU hotplug online operation. Since the failure occurs within the online callback, thermal_throttle_online(), the CPU hotplug framework does not invoke the corresponding offline callback. As a result, the hardware and software resources set up during the failed operation are not torn down.
Since only thermal_throttle_add_dev() can fail, call it before setting up the rest of the resources.
--- drivers/thermal/intel/therm_throt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/thermal/intel/therm_throt.c +6 -1
@@ -528,8 +528,13 @@ static int thermal_throttle_online(unsigned int cpu) {struct thermal_state *state = &per_cpu (thermal_state, cpu);struct device *dev =get_cpu_device (cpu); +int err;u32 l; + err =thermal_throttle_add_dev (dev, cpu); +if (err) +return err; + state->package_throttle.level =PACKAGE_LEVEL ; state->core_throttle.level =CORE_LEVEL ;
@@ -547,7 +552,7 @@ static int thermal_throttle_online(unsigned int cpu) l =apic_read (APIC_LVTTHMR );apic_write (APIC_LVTTHMR , l & ~APIC_LVT_MASKED ); -return thermal_throttle_add_dev (dev, cpu); +return err; }static int thermal_throttle_offline (unsigned int cpu)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 586/1276 ACPI: resource: Amend kernel-doc style
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 78ad5c7722b7bed9d35ffc5b45eb0f12e2c22fee ]
The functions are referred as func() in the kernel-doc. The % (percent) character makes the rendering for constants as described in the respective documentation. Amend all these.
--- drivers/acpi/resource.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/acpi/resource.c +3 -3
@@ -863,7 +863,7 @@ bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index,EXPORT_SYMBOL_GPL (acpi_dev_resource_interrupt);/** -* acpi_dev_free_resource_list - Free resource from %acpi_dev_get_resources(). +* acpi_dev_free_resource_list - Free resource from acpi_dev_get_resources(). * @list: The head of the resource list to free. */ void acpi_dev_free_resource_list (struct list_head *list)
@@ -983,7 +983,7 @@ static int __acpi_dev_get_resources(struct acpi_device *adev,* * The resultant struct resource objects are put on the list pointed to by * @list, that must be empty initially, as members of struct resource_entry -* objects. Callers of this routine should use %acpi_dev_free_resource_list() to +* objects. Callers of this routine should use acpi_dev_free_resource_list() to * free that list. * * The number of resources in the output list is returned on success, an error
@@ -1024,7 +1024,7 @@ static int is_memory(struct acpi_resource *ares, void *not_used)* The resultant struct resource objects are put on the list pointed to * by @list, that must be empty initially, as members of struct * resource_entry objects. Callers of this routine should use -* %acpi_dev_free_resource_list() to free that list. +* acpi_dev_free_resource_list() to free that list. * * The number of resources in the output list is returned on success, * an error code reflecting the error condition is returned otherwise.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 587/1276 ACPI: IPMI: Fix inverted interface check in ipmi_bmc_gone()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
[ Upstream commit 71b57aca295d61276a60e131d8f62b0cc7cf1a35 ]
Before commit a1a69b297e47 ("ACPI / IPMI: Fix race caused by the unprotected ACPI IPMI user"), ipmi_bmc_gone() skipped entries whose interface number did not match the SMI being removed, then killed the matching entry:
if (ipmi_device->ipmi_ifnum != iface) continue; __ipmi_dev_kill(ipmi_device);
That commit folded the removal block into the existing non-match test while converting the object lifetime handling, but left the comparison unchanged. The old != meant "continue past this entry"; after the refactor it meant "kill this entry".
As a result, a single ACPI IPMI interface is never removed when its SMI disappears. If multiple interfaces are tracked, the first interface whose number differs from iface is removed instead, while the interface that actually disappeared remains on driver_data.ipmi_devices. The stale entry is not marked dead and can continue to be selected for ACPI IPMI transactions. It can also prevent the same ACPI handle from being registered again.
Change the comparison to == so ipmi_bmc_gone() removes exactly the interface reported as gone by the SMI watcher. This restores the pre-a1a69b297e47 behavior and is the correct interface matching logic.
--- drivers/acpi/acpi_ipmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_ipmi.c +1 -1
@@ -490,7 +490,7 @@ static void ipmi_bmc_gone(int iface)mutex_lock (&driver_data.ipmi_lock);list_for_each_entry_safe (iter, temp, &driver_data.ipmi_devices, head) { -if (iter->ipmi_ifnum != iface) { +if (iter->ipmi_ifnum == iface) { ipmi_device = iter;__ipmi_dev_kill (iter);break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 588/1276 ieee802154: Remove WARN_ON() in cfg802154_pernet_exit()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Abramov <[email protected]>
[ Upstream commit e69ed6fc9fb3b386b5fcdb9f51623f122cee2ebd ]
There's no need to call WARN_ON() in cfg802154_pernet_exit(), since every point of failure in cfg802154_switch_netns() is covered with WARN_ON(), so remove it.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
--- net/ieee802154/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ieee802154/core.c +1 -1
@@ -351,7 +351,7 @@ static void __net_exit cfg802154_pernet_exit(struct net *net)rtnl_lock ();list_for_each_entry (rdev, &cfg802154_rdev_list, list) {if (net_eq (wpan_phy_net (&rdev->wpan_phy), net)) -WARN_ON (cfg802154_switch_netns (rdev, &init_net)); +cfg802154_switch_netns (rdev, &init_net); }rtnl_unlock (); }
Signature · 1 line
2.53.0
Re: [PATCH 6.12 0588/1276] ieee802154: Remove WARN_ON() in cfg802154_pernet_exit()
Hi Greg/Sasha,
Quoted 4 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
Quoted 8 lines
From: Ivan Abramov <[email protected]>
[ Upstream commit
e69ed6fc9fb3b386b5fcdb9f51623f122cee2ebd]There's no need to call
WARN_ON()incfg802154_pernet_exit(), since every point of failure incfg802154_switch_netns()is covered withWARN_ON(), so remove it.
that's not true for 6.12.y
I have run an AI-assisted backport review and verified one issue with 6822cd462aed ("ieee802154: Remove WARN_ON() in cfg802154_pernet_exit()").
Upstream e69ed6fc9fb3 removes the caller WARN_ON() only after 0569f67ed6a7 ("ieee802154: Avoid calling WARN_ON() on -ENOMEM in cfg802154_switch_netns()") adds warning coverage to the initial dev_change_net_namespace() failure.
In 6.12.y, cfg802154_switch_netns() still just breaks on that error, while the backport removes the caller WARN_ON(), so a non--ENOMEM failure on this path becomes silent.
So I think we should drop this patch for now until 0569f67ed6a7 ("ieee802154: Avoid calling WARN_ON() on -ENOMEM in cfg802154_switch_netns()") is backported. Thats not a clean cherry-pick and needs adaption which I think we could do later ?
Thanks,
harshit
Quoted 28 lines
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Fixes 66e5c2672cd1 ("ieee802154: add netns support")Reviewed-by Miquel Raynal <[email protected]>Signed-off-by Ivan Abramov <[email protected]>Signed-off-by Stefan Schmidt <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- net/ieee802154/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ieee802154/core.c +1
-1@@ -351,7 +351,7 @@ static void __net_exit cfg802154_pernet_exit(struct net *net)rtnl_lock ();list_for_each_entry (rdev, &cfg802154_rdev_list, list) {if (net_eq (wpan_phy_net (&rdev->wpan_phy), net)) -WARN_ON (cfg802154_switch_netns (rdev, &init_net)); +cfg802154_switch_netns (rdev, &init_net); }rtnl_unlock(); }
Sasha Levin
maintainerRe: [PATCH 6.12 0588/1276] ieee802154: Remove WARN_ON() in cfg802154_pernet_exit()
Quoted 4 lines
So I think we should drop this patch for now until
0569f67ed6a7("ieee802154: Avoid callingWARN_ON()on-ENOMEMincfg802154_switch_netns()") is backported. Thats not a clean cherry-pick and needs adaption which I think we could do later ?
You're right about the missing coverage, but I'd rather keep the patch as-is. The prerequisite 0569f67ed6a7 doesn't backport cleanly here (it needs the netns_local -> netns_immutable rename chain and the goto-errout restructure, none of which are on 6.12 and older), and the only downside of removing the caller WARN_ON() without it is that a non--ENOMEM failure on the initial dev_change_net_namespace() break path becomes silent. That's a lost warning on a rare error path, not a crash, so I'll leave the queued patch in rather than churn the chain. Thanks for the careful review.
Signature · 2 lines
Thanks, Sasha
Re: [PATCH 6.12 0588/1276] ieee802154: Remove WARN_ON() in cfg802154_pernet_exit()
Hi Sasha,
Quoted 9 lines · Sasha Levin
Quoted 4 lines
So I think we should drop this patch for now until
0569f67ed6a7("ieee802154: Avoid callingWARN_ON()on-ENOMEMincfg802154_switch_netns()") is backported. Thats not a clean cherry-pick and needs adaption which I think we could do later ?You're right about the missing coverage, but I'd rather keep the patch as-is. The prerequisite
0569f67ed6a7doesn't backport cleanly here (it needs thenetns_local->netns_immutablerename chain and the goto-errout restructure, none of which are on 6.12 and older),
Right, exactly that makes in not a clean backport.
Quoted 5 lines
and the
only downside of removing the callerWARN_ON()without it is that a non--ENOMEM failure on the initialdev_change_net_namespace()break path becomes silent. That's a lost warning on a rare error path, not a crash, so I'll leave the queued patch in rather than churn the chain.
So are we considering backporting the prereq in future releases ?
Asking this because panic_on_warn() is set in few systems probably.
Thanks,
harshit
Quoted 3 lines
Thanks
for the careful review.
Sasha Levin
maintainerRe: [PATCH 6.12 0588/1276] ieee802154: Remove WARN_ON() in cfg802154_pernet_exit()
Quoted 3 lines · Harshit Mogalapalli
So are we considering backporting the prereq in future releases ?
Asking this because
panic_on_warn()is set in few systems probably.
I had another look, and I don't want to open-code it myself.
Miquel, Ivan: could you send an adapted [PATCH 5.10/5.15/6.1/6.6/6.12] of the a2e06b4bef20 + 0569f67ed6a7 pair? That would restore parity with 7.1 and 6.18, where both went in cleanly, and I'd rather take that from you than guess at the adaptation here.
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 589/1276 ieee802154: fix kernel-infoleak in dgram_recvmsg()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aleksandr Nogikh <[email protected]>
[ Upstream commit 4db86f8ab11b5a41bfc36680be837e6ac1375ec6 ]
KMSAN reported a kernel-infoleak in move_addr_to_user():
BUG: KMSAN: kernel-infoleak in instrument_copy_to_user include/linux/instrumented.h:131 [inline] BUG: KMSAN: kernel-infoleak in _inline_copy_to_user include/linux/uaccess.h:205 [inline] BUG: KMSAN: kernel-infoleak in _copy_to_user+0xcc/0x120 lib/usercopy.c:26 instrument_copy_to_user include/linux/instrumented.h:131 [inline] _inline_copy_to_user include/linux/uaccess.h:205 [inline] _copy_to_user+0xcc/0x120 lib/usercopy.c:26 copy_to_user include/linux/uaccess.h:236 [inline] move_addr_to_user+0x2e7/0x440 net/socket.c:302 ____sys_recvmsg+0x232/0x610 net/socket.c:2925 ... Uninit was stored to memory at: ieee802154_addr_to_sa include/net/ieee802154_netdev.h:369 [inline] dgram_recvmsg+0xa09/0xbe0 net/ieee802154/socket.c:739
The issue occurs because the pan_id field of struct ieee802154_addr is left uninitialized when the address mode is IEEE802154_ADDR_NONE. The execution flow is as follows:
1. __ieee802154_rx_handle_packet() declares a local struct ieee802154_hdr hdr on the stack.
2. ieee802154_hdr_pull() calls ieee802154_hdr_get_addr() to parse the source and destination addresses into this structure.
3. If the address mode is IEEE802154_ADDR_NONE, ieee802154_hdr_get_addr() previously only set the mode field, leaving the pan_id field containing uninitialized stack memory.
4. This uninitialized pan_id is later copied into a struct sockaddr_ieee802154 in dgram_recvmsg() via ieee802154_addr_to_sa().
5. Finally, move_addr_to_user() copies the socket address structure to user space, leaking the uninitialized bytes.
Fix this by using memset to zero out the address structure in ieee802154_hdr_get_addr() when the mode is IEEE802154_ADDR_NONE.
--- net/ieee802154/header_ops.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/ieee802154/header_ops.c +6 -3
@@ -173,10 +173,13 @@ ieee802154_hdr_get_addr(const u8 *buf, int mode, bool omit_pan, {int pos =0 ; - addr->mode = mode; - -if (mode ==IEEE802154_ADDR_NONE ) +if (mode ==IEEE802154_ADDR_NONE ) { +memset (addr,0 ,sizeof (*addr)); + addr->mode =IEEE802154_ADDR_NONE ;return 0 ; + } + + addr->mode = mode;if (!omit_pan) {memcpy (&addr->pan_id, buf + pos,2 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 590/1276 mac802154: Prevent overwrite return code in mac802154_perform_association()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robertus Diawan Chris <[email protected]>
[ Upstream commit 649147cb3f8b3c0c9aeba5d89d69a6ef221c12c2 ]
When assoc_status not equal to IEEE802154_ASSOCIATION_SUCCESSFUL, the return value assigned to either "-ERANGE" or "-EPERM" but this return value will be overwritten to 0 after exiting the conditional scope. So, jump to clear_assoc label to preserve the return value when assoc_status not equal to IEEE802154_ASSOCIATION_SUCCESSFUL.
This is reported by Coverity Scan as "Unused value".
--- net/mac802154/scan.c | 1 + 1 file changed, 1 insertion(+)
net/mac802154/scan.c +1 -0
@@ -594,6 +594,7 @@ int mac802154_perform_association(struct ieee802154_sub_if_data *sdata,"Negative ASSOC RESP received from %8phC: %s\n" , &ceaddr, local->assoc_status ==IEEE802154_PAN_AT_CAPACITY ? "PAN at capacity" : "access denied"); + goto clear_assoc; } ret =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 591/1276 md/raid1: free r1_bio when REQ_NOWAIT is set and read would block on retry
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abd-Alrhman Masalkhi <[email protected]>
[ Upstream commit 69ad6ce47f9bf2b9fe0ed69b042db993d33bbf12 ]
When a read is retried, raid1_read_request() may be called with a pre-allocated r1_bio. If wait_read_barrier() fails for a REQ_NOWAIT read, the bio is completed and the function returns immediately. In this case the existing r1_bio is leaked.
This fixes a leak of pre-allocated r1_bio structures for retried reads.
--- drivers/md/raid1.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/md/raid1.c +6 -0
@@ -1335,6 +1335,12 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,if (!wait_read_barrier (conf, bio->bi_iter.bi_sector, bio->bi_opf &REQ_NOWAIT )) {bio_wouldblock_error (bio); + +if (r1bio_existed) { +set_bit (R1BIO_Returned, &r1_bio->state); +raid_end_bio_io (r1_bio); + } +return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 592/1276 netfilter: ipset: Fix data race between add and dump in all hash types
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jozsef Kadlecsik <[email protected]>
[ Upstream commit 2358f7427ccd6ec8867a48205d8fcec973683a3f ]
When adding a new entry to the next position in the existing hash bucket, the position index was incremented too early and parallel dump could read it before the entry was populated with the value. Move the setting of the position index after populating the entry.
v2: Position counting fixed, noticed by Florian Westphal.
Stable-dep-of: e4b4984e28c1 ("netfilter: ipset: Don't use test_bit() in lockless RCU readers in hash types")
--- net/netfilter/ipset/ip_set_hash_gen.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +5 -2
@@ -844,7 +844,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,const struct mtype_elem *d = value;struct mtype_elem *data;struct hbucket *n, *old =ERR_PTR (-ENOENT ); -int i, j =-1 , ret; +int i, j =-1 , npos =0 , ret;bool flag_exist = flags &IPSET_FLAG_EXIST ;bool deleted = false, forceadd = false, reuse = false;u32 r, key, multi =0 , elements, maxelem;
@@ -889,6 +889,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,ext_size (AHASH_INIT_SIZE , set->dsize); goto copy_elem; } + npos = n->pos;for (i =0 ; i < n->pos; i++) {if (!test_bit (i, n->used)) {/* Reuse first deleted entry */
@@ -962,7 +963,8 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext, } copy_elem: - j = n->pos++; + j = npos; + npos = n->pos +1 ; data =ahash_data (n, j, set->dsize); copy_data: t->hregion[r].elements++;
@@ -985,6 +987,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (SET_WITH_TIMEOUT (set))ip_set_timeout_set (ext_timeout (data, set), ext->timeout);smp_mb__before_atomic (); + n->pos = npos;set_bit (j, n->used);if (old !=ERR_PTR (-ENOENT )) {rcu_assign_pointer (hbucket (t, key), n);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 593/1276 netfilter: ipset: annotate "pos" for concurrent readers/writers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jozsef Kadlecsik <[email protected]>
[ Upstream commit 7f7445840b7771338618930e45ee641104b38ed8 ]
The "pos" structure member of struct hbucket stores the first free slot in the hash bucket of a hash type of set and there are concurrent readers/writers. Annotate accesses properly.
Stable-dep-of: e4b4984e28c1 ("netfilter: ipset: Don't use test_bit() in lockless RCU readers in hash types")
--- net/netfilter/ipset/ip_set_hash_gen.h | 62 ++++++++++++++++----------- 1 file changed, 38 insertions(+), 24 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +38 -24
@@ -386,8 +386,9 @@ static void mtype_ext_cleanup(struct ip_set *set, struct hbucket *n) { int i; +u8 pos =smp_load_acquire (&n->pos); -for (i =0 ; i < n->pos; i++) +for (i =0 ; i < pos; i++)if (test_bit (i, n->used))ip_set_ext_destroy (set,ahash_data (n, i, set->dsize)); }
@@ -490,7 +491,7 @@ mtype_gc_do(struct ip_set *set, struct htype *h, struct htable *t, u32 r)#ifdef IP_SET_HASH_WITH_NETS u8 k;#endif -u8 htable_bits = t->htable_bits; +u8 pos, htable_bits = t->htable_bits;spin_lock_bh (&t->hregion[r].lock); for (i = ahash_bucket_start(r, htable_bits);
@@ -498,7 +499,8 @@ mtype_gc_do(struct ip_set *set, struct htype *h, struct htable *t, u32 r) n =__ipset_dereference (hbucket (t, i));if (!n)continue ; -for (j =0 , d =0 ; j < n->pos; j++) { + pos =smp_load_acquire (&n->pos); +for (j =0 , d =0 ; j < pos; j++) {if (!test_bit (j, n->used)) { d++;continue ;
@@ -534,7 +536,7 @@ mtype_gc_do(struct ip_set *set, struct htype *h, struct htable *t, u32 r)/* Still try to delete expired elements. */ continue ; tmp->size = n->size -AHASH_INIT_SIZE ; -for (j =0 , d =0 ; j < n->pos; j++) { +for (j =0 , d =0 ; j < pos; j++) {if (!test_bit (j, n->used))continue ; data =ahash_data (n, j, dsize);
@@ -623,7 +625,7 @@ mtype_resize(struct ip_set *set, bool retried) {struct htype *h = set->data;struct htable *t, *orig; -u8 htable_bits; +u8 pos, htable_bits;size_t hsize, dsize = set->dsize;#ifdef IP_SET_HASH_WITH_NETS u8 flags;
@@ -685,7 +687,8 @@ mtype_resize(struct ip_set *set, bool retried) n =__ipset_dereference (hbucket (orig, i));if (!n)continue ; -for (j =0 ; j < n->pos; j++) { + pos =smp_load_acquire (&n->pos); +for (j =0 ; j < pos; j++) {if (!test_bit (j, n->used))continue ; data =ahash_data (n, j, dsize);
@@ -809,9 +812,10 @@ mtype_ext_size(struct ip_set *set, u32 *elements, size_t *ext_size) {struct htype *h = set->data;const struct htable *t; -u32 i, j, r;struct hbucket *n;struct mtype_elem *data; +u32 i, j, r; +u8 pos; t =rcu_dereference_bh (h->table);for (r =0 ; r <ahash_numof_locks (t->htable_bits); r++) {
@@ -820,7 +824,8 @@ mtype_ext_size(struct ip_set *set, u32 *elements, size_t *ext_size) n =rcu_dereference_bh (hbucket (t, i));if (!n)continue ; -for (j =0 ; j < n->pos; j++) { + pos =smp_load_acquire (&n->pos); +for (j =0 ; j < pos; j++) {if (!test_bit (j, n->used))continue ; data =ahash_data (n, j, set->dsize);
@@ -844,10 +849,11 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,const struct mtype_elem *d = value;struct mtype_elem *data;struct hbucket *n, *old =ERR_PTR (-ENOENT ); -int i, j =-1 , npos =0 , ret; +int i, j =-1 , ret;bool flag_exist = flags &IPSET_FLAG_EXIST ;bool deleted = false, forceadd = false, reuse = false;u32 r, key, multi =0 , elements, maxelem; +u8 npos =0 ;rcu_read_lock_bh (); t =rcu_dereference_bh (h->table);
@@ -889,8 +895,8 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,ext_size (AHASH_INIT_SIZE , set->dsize); goto copy_elem; } - npos = n->pos; -for (i =0 ; i < n->pos; i++) { + npos =smp_load_acquire (&n->pos); +for (i =0 ; i < npos; i++) {if (!test_bit (i, n->used)) {/* Reuse first deleted entry */ if (j ==-1 ) {
@@ -934,7 +940,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (elements >= maxelem) goto set_full;/* Create a new slot */ -if (n->pos >= n->size) { +if (npos >= n->size) {#ifdef IP_SET_HASH_WITH_MULTI if (h->bucketsize >=AHASH_MAX_TUNED ) goto set_full;
@@ -963,8 +969,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext, } copy_elem: - j = npos; - npos = n->pos +1 ; + j = npos++; data =ahash_data (n, j, set->dsize); copy_data: t->hregion[r].elements++;
@@ -987,7 +992,8 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (SET_WITH_TIMEOUT (set))ip_set_timeout_set (ext_timeout (data, set), ext->timeout);smp_mb__before_atomic (); - n->pos = npos; +/* Ensure all data writes are visible before updating position */ +smp_store_release (&n->pos, npos);set_bit (j, n->used);if (old !=ERR_PTR (-ENOENT )) {rcu_assign_pointer (hbucket (t, key), n);
@@ -1046,6 +1052,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,int i, j, k, r, ret = -IPSET_ERR_EXIST ;u32 key, multi =0 ;size_t dsize = set->dsize; +u8 pos;/* Userspace add and resize is excluded by the mutex. * Kernespace add does not trigger resize.
@@ -1061,7 +1068,8 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, n =rcu_dereference_bh (hbucket (t, key));if (!n) goto out; -for (i =0 , k =0 ; i < n->pos; i++) { + pos =smp_load_acquire (&n->pos); +for (i =0 , k =0 ; i < pos; i++) {if (!test_bit (i, n->used)) { k++;continue ;
@@ -1075,8 +1083,8 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, ret =0 ;clear_bit (i, n->used);smp_mb__after_atomic (); -if (i +1 == n->pos) - n->pos--; +if (i +1 == pos) +smp_store_release (&n->pos, --pos); t->hregion[r].elements--;#ifdef IP_SET_HASH_WITH_NETS for (j =0 ; j <IPSET_NET_COUNT ; j++)
@@ -1098,11 +1106,11 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, x->flags = flags; } } -for (; i < n->pos; i++) { +for (; i < pos; i++) {if (!test_bit (i, n->used)) k++; } -if (k == n->pos) { +if (k == pos) { t->hregion[r].ext_size -=ext_size (n->size, dsize);rcu_assign_pointer (hbucket (t, key),NULL );kfree_rcu (n, rcu);
@@ -1113,7 +1121,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (!tmp) goto out; tmp->size = n->size -AHASH_INIT_SIZE ; -for (j =0 , k =0 ; j < n->pos; j++) { +for (j =0 , k =0 ; j < pos; j++) {if (!test_bit (j, n->used))continue ; data =ahash_data (n, j, dsize);
@@ -1174,6 +1182,7 @@ mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d,int ret, i, j =0 ;#endif u32 key, multi =0 ; +u8 pos;pr_debug ("test by nets\n" );for (; j <NLEN && h->nets[j].cidr[0 ] && !multi; j++) {
@@ -1191,7 +1200,8 @@ mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d, n =rcu_dereference_bh (hbucket (t, key));if (!n)continue ; -for (i =0 ; i < n->pos; i++) { + pos =smp_load_acquire (&n->pos); +for (i =0 ; i < pos; i++) {if (!test_bit (i, n->used))continue ; data =ahash_data (n, i, set->dsize);
@@ -1225,6 +1235,7 @@ mtype_test(struct ip_set *set, void *value, const struct ip_set_ext *ext,struct mtype_elem *data;int i, ret =0 ;u32 key, multi =0 ; +u8 pos;rcu_read_lock_bh (); t =rcu_dereference_bh (h->table);
@@ -1247,7 +1258,8 @@ mtype_test(struct ip_set *set, void *value, const struct ip_set_ext *ext, ret =0 ; goto out; } -for (i =0 ; i < n->pos; i++) { + pos =smp_load_acquire (&n->pos); +for (i =0 ; i < pos; i++) {if (!test_bit (i, n->used))continue ; data =ahash_data (n, i, set->dsize);
@@ -1364,6 +1376,7 @@ mtype_list(const struct ip_set *set,/* We assume that one hash bucket fills into one page */ void *incomplete;int i, ret =0 ; +u8 pos; atd =nla_nest_start (skb,IPSET_ATTR_ADT );if (!atd)
@@ -1382,7 +1395,8 @@ mtype_list(const struct ip_set *set, cb->args[IPSET_CB_ARG0], t, n);if (!n)continue ; -for (i =0 ; i < n->pos; i++) { + pos =smp_load_acquire (&n->pos); +for (i =0 ; i < pos; i++) {if (!test_bit (i, n->used))continue ; e =ahash_data (n, i, set->dsize);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 594/1276 netfilter: ipset: Dont use test_bit() in lockless RCU readers in hash types
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jozsef Kadlecsik <[email protected]>
[ Upstream commit e4b4984e28c16406ecb318444dea4a8bf47def3e ]
Sashiko pointed out that there are a few lockless RCU readers using test_bit() which is a relaxed atomic operation and provides no memory barrier guarantees. Use test_bit_acquire() instead where the operation may run parallel with add/del/gc, i.e. is not one from the next cases
- protected by region lock
- in a set destroy phase
- in a new/temporary set creation phase
--- net/netfilter/ipset/ip_set_hash_gen.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +5 -5
@@ -689,7 +689,7 @@ mtype_resize(struct ip_set *set, bool retried)continue ; pos =smp_load_acquire (&n->pos);for (j =0 ; j < pos; j++) { -if (!test_bit (j, n->used)) +if (!test_bit_acquire (j, n->used))continue ; data =ahash_data (n, j, dsize);if (SET_ELEM_EXPIRED (set, data))
@@ -826,7 +826,7 @@ mtype_ext_size(struct ip_set *set, u32 *elements, size_t *ext_size)continue ; pos =smp_load_acquire (&n->pos);for (j =0 ; j < pos; j++) { -if (!test_bit (j, n->used)) +if (!test_bit_acquire (j, n->used))continue ; data =ahash_data (n, j, set->dsize);if (!SET_ELEM_EXPIRED (set, data))
@@ -1202,7 +1202,7 @@ mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d,continue ; pos =smp_load_acquire (&n->pos);for (i =0 ; i < pos; i++) { -if (!test_bit (i, n->used)) +if (!test_bit_acquire (i, n->used))continue ; data =ahash_data (n, i, set->dsize);if (!mtype_data_equal (data, d, &multi))
@@ -1260,7 +1260,7 @@ mtype_test(struct ip_set *set, void *value, const struct ip_set_ext *ext, } pos =smp_load_acquire (&n->pos);for (i =0 ; i < pos; i++) { -if (!test_bit (i, n->used)) +if (!test_bit_acquire (i, n->used))continue ; data =ahash_data (n, i, set->dsize);if (!mtype_data_equal (data, d, &multi))
@@ -1397,7 +1397,7 @@ mtype_list(const struct ip_set *set,continue ; pos =smp_load_acquire (&n->pos);for (i =0 ; i < pos; i++) { -if (!test_bit (i, n->used)) +if (!test_bit_acquire (i, n->used))continue ; e =ahash_data (n, i, set->dsize);if (SET_ELEM_EXPIRED (set, e))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 595/1276 netfilter: ipset: fix order of kfree_rcu() and rcu_assign_pointer()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jozsef Kadlecsik <[email protected]>
[ Upstream commit 3ca9982a8882470aa0ac4e8bb9a552b181d1efcd ]
Sashiko pointed out that kfree_rcu() was called before rcu_assign_pointer() in handling the comment extension. Fix the order so that rcu_assign_pointer() called first.
--- net/netfilter/ipset/ip_set_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipset/ip_set_core.c +2 -2
@@ -351,8 +351,8 @@ ip_set_init_comment(struct ip_set *set, struct ip_set_comment *comment,if (unlikely (c)) { set->ext_size -=sizeof (*c) +strlen (c->str) +1 ; -kfree_rcu (c, rcu);rcu_assign_pointer (comment->c,NULL ); +kfree_rcu (c, rcu); }if (!len)return ;
@@ -393,8 +393,8 @@ ip_set_comment_free(struct ip_set *set, void *ptr)if (unlikely (!c))return ; set->ext_size -=sizeof (*c) +strlen (c->str) +1 ; -kfree_rcu (c, rcu);rcu_assign_pointer (comment->c,NULL ); +kfree_rcu (c, rcu); }typedef void (*destroyer )(struct ip_set *,void *);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 596/1276 netfilter: ipset: make sure gc is properly stopped
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jozsef Kadlecsik <[email protected]>
[ Upstream commit 4a597a87e2e2f608edb6be2c510dc826b4fdfb53 ]
Sashiko noticed that when destroying a set,cancel_delayed_work_sync() was called while gc
calls queue_delayed_work() unconditionally which
can lead not to properly shutting down the gc.
--- net/netfilter/ipset/ip_set_hash_gen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_gen.h +1 -1
@@ -606,7 +606,7 @@ mtype_cancel_gc(struct ip_set *set)struct htype *h = set->data;if (SET_WITH_TIMEOUT (set)) -cancel_delayed_work_sync (&h->gc.dwork); +disable_delayed_work_sync (&h->gc.dwork); } static int
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 597/1276 netfilter: nf_reject: skip iphdr options when looking for icmp header
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit af8d6ae09c0a5f8b8a0d5680203c74b3c1daa85b ]
Not a big deal but this hould have used the real ip header length and not the base header size. As-is, if there are options then nf_skb_is_icmp_unreach() result will be random.
--- net/ipv4/netfilter/nf_reject_ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/netfilter/nf_reject_ipv4.c +1 -1
@@ -80,7 +80,7 @@ static bool nf_skb_is_icmp_unreach(const struct sk_buff *skb)if (iph->protocol !=IPPROTO_ICMP )return false; - thoff =skb_network_offset (skb) +sizeof (*iph); + thoff =skb_network_offset (skb) +ip_hdrlen (skb); tp = skb_header_pointer(skb, thoff + offsetof(struct icmphdr, type),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 598/1276 netfilter: nft_meta_bridge: fix NFT_META_BRI_IIFPVID stack leak
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 27dd2997746d54ebc079bb13161cc1bdd401d4a6 ]
This needs to test for nonzero retval.
--- net/bridge/netfilter/nft_meta_bridge.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/bridge/netfilter/nft_meta_bridge.c +3 -1
@@ -44,7 +44,9 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr,if (!br_dev || !br_vlan_enabled (br_dev)) goto err; -br_vlan_get_pvid_rcu (in, &p_pvid); +if (br_vlan_get_pvid_rcu (in, &p_pvid)) + goto err; +nft_reg_store16 (dest, p_pvid);return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 599/1276 mailbox: imx: Forward the timeout/ error in imx_mu_generic_tx()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit 82ef9a635d7130ca27ec9dd88c16afc39c83a4e8 ]
imx_mu_generic_tx() for the IMX_MU_TYPE_TXDB_V2 type polls on a register which may timeout and is recognized as an error. This error is siltently dropped and not dropped to the caller.
Forward the error to the caller.
--- drivers/mailbox/imx-mailbox.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mailbox/imx-mailbox.c +2 -1
@@ -229,6 +229,7 @@ static int imx_mu_generic_tx(struct imx_mu_priv *priv,u32 val;int ret, count; + ret =0 ;switch (cp->type) {case IMX_MU_TYPE_TX :imx_mu_write (priv, *arg, priv->dcfg->xTR + cp->idx *4 );
@@ -261,7 +262,7 @@ static int imx_mu_generic_tx(struct imx_mu_priv *priv,return -EINVAL ; } -return 0 ; +return ret; } static int imx_mu_generic_rx(struct imx_mu_priv *priv,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 600/1276 irqchip/crossbar: Fix parent domain resource leak
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bhargav Joshi <[email protected]>
[ Upstream commit a1074dd62faa6572921d387e8a21589ccea00efc ]
irq_domain_alloc_irqs_parent() is called in allocate_gic_irq() but irq_domain_free_irqs_parent() is never called which causes a resource leak.
Fix this by calling irq_domain_free_irqs_parent() in crossbar_domain_free().
--- drivers/irqchip/irq-crossbar.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-crossbar.c +1 -0
@@ -163,6 +163,7 @@ static void crossbar_domain_free(struct irq_domain *domain, unsigned int virq, cb->write (d->hwirq, cb->safe_map); }raw_spin_unlock (&cb->lock); +irq_domain_free_irqs_parent (domain, virq, nr_irqs); } static int crossbar_domain_translate(struct irq_domain *d,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 601/1276 selftests/mm: restore default nr_hugepages value via exit trap in charge_reserved_hugetlb.sh
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit a3f66e9b6e4dad38444656ffc28c28c33a4d4e1f ]
Patch series "selftests/mm: fix failures and robustness improvements", v7.
Powerpc systems with a 64K base page size exposed several issues while running mm selftests. Some tests assume specific hugetlb configurations, use incorrect interfaces, or fail instead of skipping when the required kernel features are not available.
This series fixes these issues and improves test robustness.
This patch (of 13):
cleanup() resets nr_hugepages to 0 on every invocation, while the test reconfigures it again in the next iteration. This leads to repeated allocation and freeing of large numbers of hugepages, especially when the original value is high.
Additionally, with set -e, failures in earlier cleanup steps (e.g., rmdir or umount returning EBUSY while background activity is still ongoing) can cause the script to exit before restoring the original value, leaving the system in a modified state.
Introduce a trap on EXIT, INT, and TERM to restore the original nr_hugepages value once at script termination. This avoids unnecessary allocation churn and ensures the original value is reliably restored on all exit paths.
--- tools/testing/selftests/mm/charge_reserved_hugetlb.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/mm/charge_reserved_hugetlb.sh +1 -2
@@ -12,6 +12,7 @@ if [[ $(id -u) -ne 0 ]]; then fi nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages) +trap 'echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages' EXIT INT TERM fault_limit_file=limit_in_bytes reservation_limit_file=rsvd.limit_in_bytes
@@ -65,7 +66,6 @@ function cleanup() { if [[ -e $cgroup_path/hugetlb_cgroup_test2 ]]; then rmdir $cgroup_path/hugetlb_cgroup_test2 fi - echo 0 >/proc/sys/vm/nr_hugepages echo CLEANUP DONE }
@@ -585,4 +585,3 @@ if [[ $do_umount ]]; then rmdir $cgroup_path fi -echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 602/1276 selftest/mm: register existing mapping with userfaultfd in hugetlb-mremap
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 1df31d5ef58dc6bdf0f2a8b809152d835c60b28e ]
Previously, register_region_with_uffd() created a new anonymous mapping and overwrote the address supplied by the caller before registering the range with userfaultfd.
As a result, userfaultfd was applied to an unrelated anonymous mapping instead of the hugetlb region used by the test.
Remove the extra mmap() and register the caller-provided address range directly using UFFDIO_REGISTER_MODE_MISSING, so that faults are generated for the hugetlb mapping used by the test.
This ensures userfaultfd operates on the actual hugetlb test region and validates the expected fault handling.
Before patch:
running ./hugetlb-mremap
-------------------------
TAP version 13
1..1
Map haddr: Returned address is 0x7eaa40000000 Map daddr: Returned address is 0x7daa40000000 Map vaddr: Returned address is 0x7faa40000000 Address returned by mmap() = 0x7fff9d000000
Mremap: Returned address is 0x7faa40000000 First hex is 0
First hex is 3020100
ok 1 Read same data
Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 [PASS]
ok 1 hugetlb-mremap
After patch:
running ./hugetb-mremap
-------------------------
TAP version 13
1..1
Map haddr: Returned address is 0x7eaa40000000
Map daddr: Returned address is 0x7daa40000000
Map vaddr: Returned address is 0x7faa40000000 Registered memory at address 0x7eaa40000000 with userfaultfd
Mremap: Returned address is 0x7faa40000000
First hex is 0
First hex is 3020100
ok 1 Read same data
Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 [PASS]
ok 1 hugetlb-mremap
--- tools/testing/selftests/mm/hugepage-mremap.c | 21 +++++--------------- 1 file changed, 5 insertions(+), 16 deletions(-)
tools/testing/selftests/mm/hugepage-mremap.c +5 -16
@@ -75,25 +75,14 @@ static void register_region_with_uffd(char *addr, size_t len)if (ioctl (uffd,UFFDIO_API , &uffdio_api) ==-1 )ksft_exit_fail_msg ("ioctl-UFFDIO_API: %s\n" ,strerror (errno)); -/* Create a private anonymous mapping. The memory will be -* demand-zero paged--that is, not yet allocated. When we -* actually touch the memory, it will be allocated via -* the userfaultfd. -*/ - - addr =mmap (NULL , len,PROT_READ |PROT_WRITE , -MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 ); -if (addr ==MAP_FAILED ) -ksft_exit_fail_msg ("mmap: %s\n" ,strerror (errno)); - -ksft_print_msg ("Address returned by mmap() = %p\n" , addr); - -/* Register the memory range of the mapping we just created for -* handling by the userfaultfd object. In mode, we request to track -* missing pages (i.e., pages that have not yet been faulted in). +/* Register the passed memory range for handling by the userfaultfd object. +* In mode, we request to track missing pages +* (i.e., pages that have not yet been faulted in). */ if (uffd_register (uffd, addr, len, true, false, false))ksft_exit_fail_msg ("ioctl-UFFDIO_REGISTER: %s\n" ,strerror (errno)); + +ksft_print_msg ("Registered memory at address %p with userfaultfd\n" , addr); }int main (int argc,char *argv[])
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 603/1276 selftests/mm: ensure destination is hugetlb-backed in hugetlb-mremap
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit f20ca8972e83f111c4300c60d74314568c8964bc ]
The hugetlb-mremap selftest reserves the destination address using a anonymous base-page mapping before calling mremap() with MREMAP_FIXED, while the source region is hugetlb-backed.
When remapping a hugetlb mapping into a base-page VMA may fail with:
mremap: Device or resource busy
This is observed on powerpc hash MMU systems where slice constraints and page size incompatibilities prevent the remap.
Ensure the destination region is created using MAP_HUGETLB so that both source and destination VMAs are hugetlb-backed and compatible.
Update the FLAGS macro to include MAP_HUGETLB | MAP_SHARED so that both mappings are hugetlb-backed and compatible. Also use the macro for the mmap() calls to avoid repeating the flag combination.
This ensures the test reliably exercises hugetlb mremap instead of failing due to VMA type mismatch.
--- tools/testing/selftests/mm/hugepage-mremap.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
tools/testing/selftests/mm/hugepage-mremap.c +4 -7
@@ -31,7 +31,7 @@#define MB_TO_BYTES (x) (x * 1024 * 1024)#define PROTECTION (PROT_READ | PROT_WRITE | PROT_EXEC) -#define FLAGS (MAP_SHARED | MAP_ANONYMOUS) +#define FLAGS (MAP_HUGETLB | MAP_SHARED)static void check_bytes (char *addr) {
@@ -111,23 +111,20 @@ int main(int argc, char *argv[])/* mmap to a PUD aligned address to hopefully trigger pmd sharing. */ unsigned long suggested_addr =0x7eaa40000000 ; -void *haddr =mmap ((void *)suggested_addr, length,PROTECTION , -MAP_HUGETLB |MAP_SHARED |MAP_POPULATE , fd,0 ); +void *haddr =mmap ((void *)suggested_addr, length,PROTECTION ,FLAGS , fd,0 );ksft_print_msg ("Map haddr: Returned address is %p\n" , haddr);if (haddr ==MAP_FAILED )ksft_exit_fail_msg ("mmap1: %s\n" ,strerror (errno));/* mmap again to a dummy address to hopefully trigger pmd sharing. */ suggested_addr =0x7daa40000000 ; -void *daddr =mmap ((void *)suggested_addr, length,PROTECTION , -MAP_HUGETLB |MAP_SHARED |MAP_POPULATE , fd,0 ); +void *daddr =mmap ((void *)suggested_addr, length,PROTECTION ,FLAGS , fd,0 );ksft_print_msg ("Map daddr: Returned address is %p\n" , daddr);if (daddr ==MAP_FAILED )ksft_exit_fail_msg ("mmap3: %s\n" ,strerror (errno)); suggested_addr =0x7faa40000000 ; -void *vaddr = -mmap ((void *)suggested_addr, length,PROTECTION ,FLAGS ,-1 ,0 ); +void *vaddr =mmap ((void *)suggested_addr, length,PROTECTION ,FLAGS , fd,0 );ksft_print_msg ("Map vaddr: Returned address is %p\n" , vaddr);if (vaddr ==MAP_FAILED )ksft_exit_fail_msg ("mmap2: %s\n" ,strerror (errno));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 604/1276 selftests/mm: clarify alternate unmapping in compaction_test
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 69ba1d76d93ab818245333cf400928477ba72053 ]
Add a comment explaining that every other entry in the list is unmapped to intentionally create fragmentation with locked pages before invoking check_compaction().
--- tools/testing/selftests/mm/compaction_test.c | 3 +++ 1 file changed, 3 insertions(+)
tools/testing/selftests/mm/compaction_test.c +3 -0
@@ -261,6 +261,9 @@ int main(int argc, char **argv) mem_fragmentable_MB -=MAP_SIZE_MB ; } +/* Unmap every other entry in the list to create fragmentation with +* locked pages before invoking check_compaction(). +*/ for (entry = list; entry !=NULL ; entry = entry->next) {munmap (entry->map,MAP_SIZE );if (!entry->next)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 605/1276 selftests/mm: allow PUD-level entries in compound testcase of hmm tests
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 224ed0e019b122d08580362abe57574a78f2b5fa ]
Patch series "selftests/mm: assorted fixes for hmm-tests", v3.
This series fixes a few issues in hmm-tests that show up when page-size and huge-page configuration differ from the hardcoded assumptions the tests were written for (PMD/THP sizing, default hugepage size, and related cases).
It also includes a fix to exclusive_cow: the test ignored the return value of fork(), so both parent and child ran the same teardown path.
This patch (of 3):
The HMM compound testcase currently assumes only PMD-level mappings and fails on systems where default_hugepagesz=1G is set, because the region is then reported by the device at PUD level.
Determine the mapping level (PMD or PUD) the device reports for the first page of the range and require every page to match that level exactly via ASSERT_EQ(). This accepts PUD-level mappings while preserving the expected/observed protection values printed on failure, and rejects a fragmented mapping that mixes PMD- and PUD-level entries within the same range (which a per-page OR check would have let pass).
--- tools/testing/selftests/mm/hmm-tests.c | 32 +++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-)
tools/testing/selftests/mm/hmm-tests.c +24 -8
@@ -1612,8 +1612,8 @@ TEST_F(hmm2, snapshot) }/* -* Test the hmm_range_fault() HMM_PFN_PMD flag for large pages that -* should be mapped by a large page table entry. +* Test the hmm_range_fault() handling of large pages (PMD or PUD) +* that should be mapped by a large page table entry. */ TEST_F(hmm, compound) {
@@ -1623,6 +1623,7 @@ TEST_F(hmm, compound)unsigned long default_hsize;int *ptr;unsigned char *m; +unsigned char prot;int ret;unsigned long i;
@@ -1661,11 +1662,20 @@ TEST_F(hmm, compound)ASSERT_EQ (ret,0 );ASSERT_EQ (buffer->cpages, npages); -/* Check what the device saw. */ +/* +* Check what the device saw. The region is backed by a single huge +* page that the device reports either at PMD or at PUD level depending +* on the configured default hugepage size. Determine that level from +* the first page and require every page in the range to match it +* exactly, so that a fragmented mapping mixing levels (or a missing +* large-page bit) is still caught and reported with its actual value. +*/ m = buffer->mirror; + prot =HMM_DMIRROR_PROT_WRITE | + ((m[0 ] &HMM_DMIRROR_PROT_PUD ) ?HMM_DMIRROR_PROT_PUD : +HMM_DMIRROR_PROT_PMD );for (i =0 ; i < npages; ++i) -ASSERT_EQ (m[i],HMM_DMIRROR_PROT_WRITE | -HMM_DMIRROR_PROT_PMD ); +ASSERT_EQ (m[i], prot);/* Make the region read-only. */ ret =mprotect (buffer->ptr, size,PROT_READ );
@@ -1676,11 +1686,17 @@ TEST_F(hmm, compound)ASSERT_EQ (ret,0 );ASSERT_EQ (buffer->cpages, npages); -/* Check what the device saw. */ +/* +* Check what the device saw after mprotect(PROT_READ). Same +* approach as above: determine the mapping level from the first +* page and require every page to match it exactly. +*/ m = buffer->mirror; + prot =HMM_DMIRROR_PROT_READ | + ((m[0 ] &HMM_DMIRROR_PROT_PUD ) ?HMM_DMIRROR_PROT_PUD : +HMM_DMIRROR_PROT_PMD );for (i =0 ; i < npages; ++i) -ASSERT_EQ (m[i],HMM_DMIRROR_PROT_READ | -HMM_DMIRROR_PROT_PMD ); +ASSERT_EQ (m[i], prot);munmap (buffer->ptr, buffer->size); buffer->ptr =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 606/1276 selftests/mm: fix exclusive_cow test fork() handling
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aboorva Devarajan <[email protected]>
[ Upstream commit cea5702144615878600d3a39b5d8b3cc34719012 ]
The test ignores the return value of fork(), so both the parent and the (newly created) child run the COW verification loops and then call hmm_buffer_free() before returning into the kselftest harness, which _exit()s each side. This duplicated teardown sequence has been observed to manifest as a SIGSEGV in the test child, e.g.:
hmm-tests[360141]: segfault (11) at 0 nip 10006964 lr 1000ac3c code 1 in hmm-tests[6964,10000000+30000]
Fix this by adopting the same fork()-then-wait pattern already used by the nearby anon_write_child / anon_write_child_shared tests in this file: the child performs the COW verification and then _exit(0)s so it does not run the test teardown, while the parent independently verifies COW, waits for the child, and only then frees the buffer.
--- tools/testing/selftests/mm/hmm-tests.c | 31 +++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)
tools/testing/selftests/mm/hmm-tests.c +28 -3
@@ -1896,6 +1896,8 @@ TEST_F(hmm, exclusive_cow)unsigned long i;int *ptr;int ret; +pid_t pid; +int status; npages =ALIGN (HMM_BUFFER_SIZE , self->page_size) >> self->page_shift;ASSERT_NE (npages,0 );
@@ -1924,14 +1926,37 @@ TEST_F(hmm, exclusive_cow)ASSERT_EQ (ret,0 );ASSERT_EQ (buffer->cpages, npages); -fork (); + pid =fork (); +if (pid ==-1 ) +ASSERT_EQ (pid,0 ); -/* Fault pages back to system memory and check them. */ +if (pid ==0 ) { +/* +* Child verifies COW independently, then _exit(0)s so it does +* not run the test teardown. A failed ASSERT_* here makes the +* harness abort() the child, so the parent sees +* !WIFEXITED(status) below and fails in turn. +*/ +for (i =0 , ptr = buffer->ptr; i < size /sizeof (*ptr); ++i) +ASSERT_EQ (ptr[i]++, i); + +for (i =0 , ptr = buffer->ptr; i < size /sizeof (*ptr); ++i) +ASSERT_EQ (ptr[i], i +1 ); + +_exit (0 ); + } + +/* Parent: also increment to verify COW works for both processes. */ for (i =0 , ptr = buffer->ptr; i < size /sizeof (*ptr); ++i)ASSERT_EQ (ptr[i]++, i);for (i =0 , ptr = buffer->ptr; i < size /sizeof (*ptr); ++i) -ASSERT_EQ (ptr[i], i+1 ); +ASSERT_EQ (ptr[i], i +1 ); + +/* Parent: wait for child and then free the buffer. */ +ASSERT_EQ (waitpid (pid, &status,0 ), pid); +ASSERT_TRUE (WIFEXITED (status)); +ASSERT_EQ (WEXITSTATUS (status),0 );hmm_buffer_free (buffer); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 607/1276 net: marvell: prestera: initialize err in prestera_port_sfp_bind
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 62b01f72d93c7bc8fde3b2e5b5f783eca5f53324 ]
prestera_port_sfp_bind() returns err after walking the ports node. If no child node matches the port's front-panel id, err is never assigned.
Initialize err to 0 because absence of a matching optional port device tree node is not an error. In that case no phylink is created and port creation should continue with port->phy_link left NULL. Errors from malformed matched nodes and phylink_create() still propagate.
--- drivers/net/ethernet/marvell/prestera/prestera_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/marvell/prestera/prestera_main.c +1 -1
@@ -372,7 +372,7 @@ static int prestera_port_sfp_bind(struct prestera_port *port)struct device_node *ports, *node;struct fwnode_handle *fwnode;struct phylink *phy_link; -int err; +int err =0 ;if (!sw->np)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 608/1276 tipc: fix use-after-free of the discoverer in tipc_disc_rcv()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 1579342d71133da7f00daa02c75cebec7372097b ]
bearer_disable() frees b->disc with tipc_disc_delete()'s plain kfree(), but tipc_disc_rcv() still dereferences b->disc in RX softirq under rcu_read_lock() (tipc_udp_recv -> tipc_rcv -> tipc_disc_rcv).
L2 bearers are safe thanks to the synchronize_net() in tipc_disable_l2_media(), but the UDP bearer defers that call to the cleanup_bearer() workqueue, so the discoverer is freed with no grace period:
BUG: KASAN: slab-use-after-free in tipc_disc_rcv (net/tipc/discover.c:149) Read of size 8 at addr ffff88802348b728 by task poc_tipc/184 <IRQ> tipc_disc_rcv (net/tipc/discover.c:149) tipc_rcv (net/tipc/node.c:2126) tipc_udp_recv (net/tipc/udp_media.c:391) udp_rcv (net/ipv4/udp.c:2643) ip_local_deliver_finish (net/ipv4/ip_input.c:241) </IRQ> Freed by task 181: kfree (mm/slub.c:6565) bearer_disable (net/tipc/bearer.c:418) tipc_nl_bearer_disable (net/tipc/bearer.c:1001)
The bearer is freed with kfree_rcu(); free the discoverer the same way. Add an rcu_head to struct tipc_discoverer and free it and its skb from an RCU callback.
Because the RCU callback (tipc_disc_free_rcu) lives in module text, a call_rcu() that is still pending when the tipc module is unloaded would invoke a freed function. Add an rcu_barrier() to tipc_exit() after the bearer subsystem has been torn down, so all pending discoverer callbacks have run before the module text goes away.
Reachable from an unprivileged user namespace: the TIPCv2 genl family is netnsok and its bearer commands have no GENL_ADMIN_PERM. Needs CONFIG_TIPC and CONFIG_TIPC_MEDIA_UDP.
--- net/tipc/core.c | 5 +++++ net/tipc/discover.c | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-)
net/tipc/core.c +5 -0
@@ -218,6 +218,11 @@ static void __exit tipc_exit(void)unregister_pernet_device (&tipc_net_ops);tipc_unregister_sysctl (); +/* TODO: Wait for all timers that called call_rcu() to finish before +* calling rcu_barrier(). +*/ +rcu_barrier (); +pr_info ("Deactivated\n" ); }
net/tipc/discover.c +12 -2
@@ -58,6 +58,7 @@* @skb: request message to be (repeatedly) sent * @timer: timer governing period between requests * @timer_intv: current interval between requests (in ms) +* @rcu: RCU head for deferred freeing */ struct tipc_discoverer {u32 bearer_id;
@@ -69,6 +70,7 @@ struct tipc_discoverer {struct sk_buff *skb;struct timer_list timer;unsigned long timer_intv; +struct rcu_head rcu; };/**
@@ -382,6 +384,15 @@ int tipc_disc_create(struct net *net, struct tipc_bearer *b,return 0 ; } +static void tipc_disc_free_rcu (struct rcu_head *rp) +{ + struct tipc_discoverer *d = container_of(rp, struct tipc_discoverer, + rcu); + +kfree_skb (d->skb); +kfree (d); +} +/** * tipc_disc_delete - destroy object sending periodic link setup requests * @d: ptr to link dest structure
@@ -389,8 +400,7 @@ int tipc_disc_create(struct net *net, struct tipc_bearer *b,void tipc_disc_delete (struct tipc_discoverer *d) {timer_shutdown_sync (&d->timer); -kfree_skb (d->skb); -kfree (d); +call_rcu (&d->rcu, tipc_disc_free_rcu); }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 609/1276 net: ethernet: mtk_ppe: Fix rhashtable leak in mtk_ppe_init error paths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wayen Yan <[email protected]>
[ Upstream commit 41782770be567abc6509169d0ffdada31c783a66 ]
In mtk_ppe_init(), when accounting is enabled, the error paths for dmam_alloc_coherent(mib) and devm_kzalloc(acct) failures return NULL directly, bypassing the err_free_l2_flows label that destroys the rhashtable initialized earlier.
While this leak only occurs during probe (not runtime) and the leaked memory is minimal (an empty rhash table), fixing it ensures proper error path cleanup consistency.
Fix by changing the two return NULL statements to goto err_free_l2_flows.
--- drivers/net/ethernet/mediatek/mtk_ppe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_ppe.c +2 -2
@@ -918,7 +918,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index) mib =dmam_alloc_coherent (ppe->dev,MTK_PPE_ENTRIES *sizeof (*mib), &ppe->mib_phys,GFP_KERNEL );if (!mib) -return NULL ; + goto err_free_l2_flows; ppe->mib_table = mib;
@@ -926,7 +926,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index) GFP_KERNEL);if (!acct) -return NULL ; + goto err_free_l2_flows; ppe->acct_table = acct; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 610/1276 octeontx2-af: mcs: Fix unsupported secy stats read
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geetha sowjanya <[email protected]>
[ Upstream commit d4b7440f7316e76f013f57d8b6da069a1b9c34e7 ]
Secy control stats counter doesn't exist for CNF10KB platform. Skip reading this respective register for CNF10KB silicon while fetching secy stats.
--- drivers/net/ethernet/marvell/octeontx2/af/mcs.c | 6 +++--- drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/mcs.c +3 -3
@@ -120,13 +120,13 @@ void mcs_get_rx_secy_stats(struct mcs *mcs, struct mcs_secy_stats *stats, int id reg =MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYUNTAGGEDX (id); stats->pkt_untaged_cnt =mcs_reg_read (mcs, reg); - reg =MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYCTLX (id); - stats->pkt_ctl_cnt =mcs_reg_read (mcs, reg); -if (mcs->hw->mcs_blks >1 ) { reg =MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYNOTAGX (id); stats->pkt_notag_cnt =mcs_reg_read (mcs, reg); +return ; } + reg =MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYCTLX (id); + stats->pkt_ctl_cnt =mcs_reg_read (mcs, reg); } void mcs_get_flowid_stats(struct mcs *mcs, struct mcs_flowid_stats *stats,
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +2 -1
@@ -505,10 +505,11 @@ static int rvu_dbg_mcs_rx_secy_stats_display(struct seq_file *filp, void *unusedseq_printf (filp,"secy%d: Tagged ctrl pkts: %lld\n" , secy_id, stats.pkt_tagged_ctl_cnt);seq_printf (filp,"secy%d: Untaged pkts: %lld\n" , secy_id, stats.pkt_untaged_cnt); -seq_printf (filp,"secy%d: Ctrl pkts: %lld\n" , secy_id, stats.pkt_ctl_cnt);if (mcs->hw->mcs_blks >1 )seq_printf (filp,"secy%d: pkts notag: %lld\n" , secy_id, stats.pkt_notag_cnt); +else +seq_printf (filp,"secy%d: Ctrl pkts: %lld\n" , secy_id, stats.pkt_ctl_cnt); }mutex_unlock (&mcs->stats_lock);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 611/1276 octeontx2-pf: Clear stats of all resources when freeing resources
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Subbaraya Sundeep <[email protected]>
[ Upstream commit fd4460721fb4062ef470ecdfdaedadfe7e415c09 ]
When all MCS resources mapped to a PF are being freed then clear stats of all those resources too.
--- drivers/net/ethernet/marvell/octeontx2/nic/cn10k_macsec.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/marvell/octeontx2/nic/cn10k_macsec.c +1 -0
@@ -213,6 +213,7 @@ static void cn10k_mcs_free_rsrc(struct otx2_nic *pfvf, enum mcs_direction dir, clear_req->id = hw_rsrc_id; clear_req->type = type; clear_req->dir = dir; + clear_req->all = all; req =otx2_mbox_alloc_msg_mcs_free_resources (mbox);if (!req)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 612/1276 octeontx2-pf: mcs: Fix mcs resources free on PF shutdown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geetha sowjanya <[email protected]>
[ Upstream commit 450d0e90b10393bd9f50c127875a9fdd4cc81c30 ]
On PF shutdown, the current driver free mcs hardware resources though mcs resources are not allocated to it. This patch checks the mcs resources status and if resources are allocated then only sends mailbox message to free them.
--- .../net/ethernet/marvell/octeontx2/nic/cn10k_macsec.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/cn10k_macsec.c +7 -2
@@ -1808,11 +1808,16 @@ int cn10k_mcs_init(struct otx2_nic *pfvf)void cn10k_mcs_free (struct otx2_nic *pfvf) { +struct cn10k_mcs_cfg *cfg = pfvf->macsec_cfg; +if (!test_bit (CN10K_HW_MACSEC , &pfvf->hw.cap_flag))return ; -cn10k_mcs_free_rsrc (pfvf,MCS_TX ,MCS_RSRC_TYPE_SECY ,0 , true); -cn10k_mcs_free_rsrc (pfvf,MCS_RX ,MCS_RSRC_TYPE_SECY ,0 , true); +if (!list_empty (&cfg->txsc_list)) { +cn10k_mcs_free_rsrc (pfvf,MCS_TX ,MCS_RSRC_TYPE_SECY ,0 , true); +cn10k_mcs_free_rsrc (pfvf,MCS_RX ,MCS_RSRC_TYPE_SECY ,0 , true); + } +kfree (pfvf->macsec_cfg); pfvf->macsec_cfg =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 613/1276 net/sched: act_ct: fix nf_connlabels leak on two error paths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit 16e088016f38cf728a0de709c3335cc5a3850476 ]
tcf_ct_fill_params() calls nf_connlabels_get() (setting put_labels) when TCA_CT_LABELS is present, but two later error sites use a bare return instead of "goto err", skipping the err: nf_connlabels_put() cleanup. They also precede the "p->put_labels = put_labels" assignment, so the tcf_ct_params_free() fallback does not release the count either. Each failed RTM_NEWACTION on these paths leaks one nf_connlabels reference:net->ct.labels_used is incremented and never released. The action is reachable with CAP_NET_ADMIN over the netns, i.e. from an unprivileged user namespace on default-userns kernels.
Impact: an unprivileged user with CAP_NET_ADMIN over a network namespace (e.g. via user namespaces) leaks one nf_connlabels reference per failed RTM_NEWACTION on the two error paths; net->ct.labels_used is never released.
The err: label is safe to reach from both sites: p->tmpl is still NULL there (kzalloc'd, not yet assigned) and nf_ct_put(NULL) is a no-op, so no inline release is needed.
--- net/sched/act_ct.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/sched/act_ct.c +4 -2
@@ -1294,7 +1294,8 @@ static int tcf_ct_fill_params(struct net *net,if (tb[TCA_CT_ZONE ]) {if (!IS_ENABLED (CONFIG_NF_CONNTRACK_ZONES )) {NL_SET_ERR_MSG_MOD (extack,"Conntrack zones isn't enabled." ); -return -EOPNOTSUPP ; + err = -EOPNOTSUPP ; + goto err; } tcf_ct_set_key_val(tb,
@@ -1307,7 +1308,8 @@ static int tcf_ct_fill_params(struct net *net, tmpl =nf_ct_tmpl_alloc (net, &zone,GFP_KERNEL );if (!tmpl) {NL_SET_ERR_MSG_MOD (extack,"Failed to allocate conntrack template" ); -return -ENOMEM ; + err = -ENOMEM ; + goto err; } p->tmpl = tmpl;if (tb[TCA_CT_HELPER_NAME ]) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 614/1276 ipv6: ndisc: fix NULL deref in accept_untracked_na()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit d186e942365acece7c56d39da05dd63bf95b280a ]
accept_untracked_na() re-fetches the inet6_dev with __in6_dev_get(dev) and dereferences idev->cnf.accept_untracked_na without a NULL check, even though its only caller ndisc_recv_na() already fetched and NULL-checked idev for the same device.
Both reads of dev->ip6_ptr run in the same RCU read-side critical section, but a concurrent addrconf_ifdown() can clear dev->ip6_ptr between them: lowering the MTU below IPV6_MIN_MTU calls addrconf_ifdown() without the synchronize_net() that orders the unregister path, so the re-fetch returns NULL and oopses:
BUG: KASAN: null-ptr-deref in ndisc_recv_na (net/ipv6/ndisc.c:974) Read of size 4 at addr 0000000000000364 Call Trace: <IRQ> ndisc_recv_na (net/ipv6/ndisc.c:974) icmpv6_rcv (net/ipv6/icmp.c:1193) ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479) ip6_input_finish (net/ipv6/ip6_input.c:534) ip6_input (net/ipv6/ip6_input.c:545) ip6_mc_input (net/ipv6/ip6_input.c:635) ipv6_rcv (net/ipv6/ip6_input.c:351) </IRQ>
It is reachable by an unprivileged user via a network namespace.
Pass the caller's already validated idev instead of re-fetching it; the idev stays alive for the whole RCU critical section, so it is safe even after dev->ip6_ptr has been cleared.
--- net/ipv6/ndisc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/ipv6/ndisc.c +3 -5
@@ -976,10 +976,8 @@ static enum skb_drop_reason ndisc_recv_ns(struct sk_buff *skb)return reason; } -static int accept_untracked_na (struct net_device *dev,struct in6_addr *saddr) +static int accept_untracked_na (struct inet6_dev *idev,struct in6_addr *saddr) { -struct inet6_dev *idev =__in6_dev_get (dev); -switch (READ_ONCE (idev->cnf.accept_untracked_na)) {case 0 :/* Don't accept untracked na (absent in neighbor cache) */ return 0 ;
@@ -989,7 +987,7 @@ static int accept_untracked_na(struct net_device *dev, struct in6_addr *saddr)* same subnet as an address configured on the interface that * received the na */ -return !!ipv6_chk_prefix (saddr, dev); +return !!ipv6_chk_prefix (saddr, idev->dev);default :return 0 ; }
@@ -1088,7 +1086,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb)*/ new_state = msg->icmph.icmp6_solicited ?NUD_REACHABLE :NUD_STALE ;if (!neigh && lladdr && idev &&READ_ONCE (idev->cnf.forwarding)) { -if (accept_untracked_na (dev, saddr)) { +if (accept_untracked_na (idev, saddr)) { neigh =neigh_create (&nd_tbl, &msg->target, dev); new_state =NUD_STALE ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 615/1276 dpaa2-switch: do not accept VLAN uppers while bridged
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ioana Ciornei <[email protected]>
[ Upstream commit d07d80b6a129a44538cda1549b7acf95154fb197 ]
The dpaa2-switch driver does not support VLAN uppers while its ports are bridged. This scenario tried to be prevented by rejecting a bridge join while VLAN uppers exist but the reverse order was still possible.
This patches adds a check so that the dpaa2-switch also does not accept VLAN uppers while bridged.
--- drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +8 -0
@@ -2197,6 +2197,7 @@ dpaa2_switch_prechangeupper_sanity_checks(struct net_device *netdev,static int dpaa2_switch_port_prechangeupper (struct net_device *netdev,struct netdev_notifier_changeupper_info *info) { +struct ethsw_port_priv *port_priv;struct netlink_ext_ack *extack;struct net_device *upper_dev;int err;
@@ -2215,6 +2216,13 @@ static int dpaa2_switch_port_prechangeupper(struct net_device *netdev,if (!info->linking)dpaa2_switch_port_pre_bridge_leave (netdev); + }else if (is_vlan_dev (upper_dev)) { + port_priv =netdev_priv (netdev); +if (port_priv->fdb->bridge_dev) { +NL_SET_ERR_MSG_MOD (extack, +"Cannot accept VLAN uppers while bridged" ); +return -EOPNOTSUPP ; + } }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 616/1276 rtc: abx80x: fix the RTC_VL_CLR clearing all status flags
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antoni Pokusinski <[email protected]>
[ Upstream commit 419719c514252a2dbb2e2976f564c83417dd6d0a ]
The RTC_VL_CLR ioctl intends to clear only the battery low flag (BLF), however the current implementation writes 0 to the status register, clearing all status bits.
Fix this by writing back the masked status value so that only BLF is cleared, preserving other status flags.
--- drivers/rtc/rtc-abx80x.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/rtc/rtc-abx80x.c +2 -1
@@ -545,7 +545,8 @@ static int abx80x_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) status &= ~ABX8XX_STATUS_BLF ; - tmp =i2c_smbus_write_byte_data (client,ABX8XX_REG_STATUS ,0 ); + tmp =i2c_smbus_write_byte_data (client,ABX8XX_REG_STATUS , + status);if (tmp <0 )return tmp;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 617/1276 rtc: ds1307: handle oscillator stop flag for ds1337/ds1339/ds3231
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ronan Dalton <[email protected]>
[ Upstream commit a091e1ba3b68cabc9caedafc6f81d9fe9b3b2200 ]
Prior to commit 48458654659c ("rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe"), the oscillator stop flag (OSF) bit was checked during device probe for the ds1337, ds1339, ds1341, and ds3231 chips; if it was set, it would be cleared and a warning would be logged saying "SET TIME!". Since that commit, the OSF bit is no longer cleared, but the warning is still printed.
Directly following that commit, there was no way to get rid of this warning because nothing cleared the OSF bit on these chips.
The commit associated with the previous commit, 523923cfd5d6 ("rtc:
ds1307: handle oscillator stop flag (OSF) for ds1341"), made proper use of the OSF when getting and setting the time in the RTC. However, the other RTC variants ds1337, ds1339 and ds3231 didn't have a corresponding change made.
Given that the OSF bit is no longer cleared at probe time when it is set, the remaining three chips should have the same handling as the ds1341 chip has for the OSF bit.
Fix the issue on the ds1337, ds1339 and ds3231 chips by applying the same logic as the ds1341 has to these chips.
Note that any devices brought up between the first referenced commit and this one may begin mistrusting the time reported by the RTC until it is set again, if the bit was never explicitly cleared.
Note that only the ds1339 was tested with this change, but the datasheets for the other chips contain essentially identical descriptions of the OSF bit so the same change should work.
--- drivers/rtc/rtc-ds1307.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
drivers/rtc/rtc-ds1307.c +17 -11
@@ -269,6 +269,16 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)if (tmp &DS1338_BIT_OSF )return -EINVAL ;break ; +case ds_1337: +case ds_1339: +case ds_1341: +case ds_3231: + ret =regmap_read (ds1307->regmap,DS1337_REG_STATUS , &tmp); +if (ret) +return ret; +if (tmp &DS1337_BIT_OSF ) +return -EINVAL ; +break ;case ds_1340:if (tmp & DS1340_BIT_nEOSC)return -EINVAL ;
@@ -279,13 +289,6 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)if (tmp &DS1340_BIT_OSF )return -EINVAL ;break ; -case ds_1341: - ret =regmap_read (ds1307->regmap,DS1337_REG_STATUS , &tmp); -if (ret) -return ret; -if (tmp &DS1337_BIT_OSF ) -return -EINVAL ; -break ;case ds_1388: ret =regmap_read (ds1307->regmap,DS1388_REG_FLAG , &tmp);if (ret)
@@ -380,14 +383,17 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)regmap_update_bits (ds1307->regmap,DS1307_REG_CONTROL ,DS1338_BIT_OSF ,0 );break ; -case ds_1340: -regmap_update_bits (ds1307->regmap,DS1340_REG_FLAG , -DS1340_BIT_OSF ,0 ); -break ; +case ds_1337: +case ds_1339:case ds_1341: +case ds_3231:regmap_update_bits (ds1307->regmap,DS1337_REG_STATUS ,DS1337_BIT_OSF ,0 );break ; +case ds_1340: +regmap_update_bits (ds1307->regmap,DS1340_REG_FLAG , +DS1340_BIT_OSF ,0 ); +break ;case ds_1388:regmap_update_bits (ds1307->regmap,DS1388_REG_FLAG ,DS1388_BIT_OSF ,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 618/1276 bpf: Fix stack slot index in nospec checks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nuoqi Gui <[email protected]>
[ Upstream commit d1d53aa30ab3b5ae89161c9cc840b3f7489ad386 ]
check_stack_write_fixed_off() computes the byte slot for a fixed-offset stack write as -off - 1, and records each written byte in slot_type[] with (slot - i) % BPF_REG_SIZE.
The Spectre v4 sanitization pre-check uses slot_type[i] instead. For a 4-byte write at fp-8 after the lower half of fp-8 has been zeroed, the pre-check scans bytes 0..3 and sees STACK_ZERO while the actual write updates bytes 7..4. That can leave the second half-slot write without nospec_result even though the bytes being overwritten still require sanitization.
Use the same slot index in the sanitization pre-check that the write path uses when updating slot_type[].
--- kernel/bpf/verifier.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +2 -1
@@ -4769,7 +4769,8 @@ static int check_stack_write_fixed_off(struct bpf_verifier_env *env,bool sanitize = reg &&is_spillable_regtype (reg->type);for (i =0 ; i < size; i++) { -u8 type = state->stack[spi].slot_type[i]; +u8 type = state->stack[spi].slot_type[(slot - i) % +BPF_REG_SIZE ];if (type !=STACK_MISC && type !=STACK_ZERO ) { sanitize = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 619/1276 bpftool: Fix vmlinux BTF leak in cgroup commands
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yichong Chen <[email protected]>
[ Upstream commit bda6a7308ef8e79cfbb7d09e48e1c7ffaa522269 ]
bpftool cgroup show and tree call libbpf_find_kernel_btf() to resolve attach_btf names, but never release the returned BTF object.
For cgroup tree, do_show_tree_fn() is called once for each cgroup visited by nftw(). When more than one cgroup has attached programs, each callback overwrites btf_vmlinux with a new object and loses the previous allocation.
Load vmlinux BTF only once during a tree walk and release it when cgroup show or tree completes. Reset btf_vmlinux_id at the same time so batch mode starts with clean state.
--- tools/bpf/bpftool/cgroup.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
tools/bpf/bpftool/cgroup.c +13 -1
@@ -74,6 +74,13 @@ static unsigned int query_flags;static struct btf *btf_vmlinux;static __u32 btf_vmlinux_id; +static void free_btf_vmlinux (void ) +{ +btf__free (btf_vmlinux); + btf_vmlinux =NULL ; + btf_vmlinux_id =0 ; +} +static enum bpf_attach_type parse_attach_type (const char *str) {const char *attach_type_str;
@@ -384,6 +391,8 @@ static int do_show(int argc, char **argv)if (json_output)jsonw_end_array (json_wtr); +free_btf_vmlinux (); + exit_cgroup:close (cgroup_fd); exit:
@@ -433,7 +442,9 @@ static int do_show_tree_fn(const char *fpath, const struct stat *sb,printf ("%s\n" , fpath); } - btf_vmlinux =libbpf_find_kernel_btf (); +if (!btf_vmlinux) + btf_vmlinux =libbpf_find_kernel_btf (); +for (i =0 ; i <ARRAY_SIZE (cgroup_attach_types); i++)show_bpf_progs (cgroup_fd, cgroup_attach_types[i], ftw->level);
@@ -536,6 +547,7 @@ static int do_show_tree(int argc, char **argv)if (json_output)jsonw_end_array (json_wtr); +free_btf_vmlinux ();free (cgroup_alloced);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 620/1276 bpf: zero-initialize the fib lookup flow struct
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avinash Duduskar <[email protected]>
[ Upstream commit 0dfcb68a6a5ac517b22dff6a1f01cb4f126dfc57 ]
bpf_ipv4_fib_lookup() and bpf_ipv6_fib_lookup() build the flow key on the stack with a bare "struct flowi4 fl4;" / "struct flowi6 fl6;" and fill it field by field, but never set flowi4_l3mdev / flowi6_l3mdev.
On the non-DIRECT path the lookup goes through the fib rules whenever the netns has custom rules, which a VRF installs:
bpf_ipv4_fib_lookup() -> fib_lookup() -> __fib_lookup() -> l3mdev_update_flow() reads !fl->flowi_l3mdev -> fib_rules_lookup() -> fib_rule_match() -> l3mdev_fib_rule_match() uses fl->flowi_l3mdev
l3mdev_update_flow() resolves the l3mdev master from the ingress device only while the field is still zero. Left at a nonzero stack value the resolution is skipped, and l3mdev_fib_rule_match() then tests that value as an ifindex, so the VRF master is not resolved and the rule fails to
match: an ingress enslaved to a VRF can fail to select its table. FIB rules matching on an L3 master device (l3mdev_fib_rule_iif_match()/ _oif_match()) read the same value, so an "ip rule iif/oif <vrf>" mismatches the same way.
Zero-initialize the whole flow struct rather than adding one more field assignment, so any flowi field added later is covered too. ip_route_input_slow() likewise zeroes the field before its input lookup.
CONFIG_INIT_STACK_ALL_ZERO masks this by default, but it depends on compiler support (CC_HAS_AUTO_VAR_INIT_ZERO), so INIT_STACK_NONE builds, including older toolchains that fall back to it, are exposed. Built with INIT_STACK_ALL_PATTERN, a plain bpf_fib_lookup (no VLAN, no DIRECT) over a VRF slave whose destination is routed only in the VRF table returns BPF_FIB_LKUP_RET_NOT_FWDED, and resolves with this patch. On the default config the lookup succeeds either way, so ordinary testing does not catch the bug.
--- net/core/filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/filter.c +2 -2
@@ -6007,7 +6007,7 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,struct neighbour *neigh;struct net_device *dev;struct fib_result res; -struct flowi4 fl4; +struct flowi4 fl4 = {};u32 mtu =0 ;int err;
@@ -6147,7 +6147,7 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params,struct neighbour *neigh;struct net_device *dev;struct inet6_dev *idev; -struct flowi6 fl6; +struct flowi6 fl6 = {};int strict =0 ;int oif, err;u32 mtu =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 621/1276 bpf: Fix effective prog array index with BPF_F_PREORDER
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amery Hung <[email protected]>
[ Upstream commit f08aaee3152d0dfc578b3f2586932d82062701dd ]
replace_effective_prog() and purge_effective_progs() located the slot in the effective array by walking the program hlist and counting entries linearly. That count does not match the array layout: compute_effective_ progs() places BPF_F_PREORDER programs at the front (ancestor cgroup first, attach order within a cgroup) and the rest after them (descendant cgroup first). So when a preorder program is present, the linear hlist position no longer equals the program's index in the effective array.
For replace_effective_prog() (bpf_link_update()) this overwrote the wrong slot, corrupting the effective order. For purge_effective_progs(), it could dummy out a slot belonging to a different program and leave the detached program in the array while bpf_prog_put() drops its reference, i.e. a use-after-free.
Fix both by replaying compute_effective_progs()'s placement (including the per-cgroup preorder reversal) in a shared effective_prog_pos() helper. Identify the entry by its struct bpf_prog_list pointer rather than by (prog, link) value, so the lookup resolves to exactly the attachment the syscall selected even when the same bpf_prog is attached to several cgroups in the hierarchy.
--- kernel/bpf/cgroup.c | 108 +++++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 46 deletions(-)
kernel/bpf/cgroup.c +62 -46
@@ -769,19 +769,65 @@ static int cgroup_bpf_attach(struct cgroup *cgrp,return ret; } +static int effective_prog_pos (struct cgroup *cgrp, +enum cgroup_bpf_attach_type atype, +struct bpf_prog_list *target_pl) +{ +int cnt =0 , preorder_cnt =0 , fstart, bstart, init_bstart, pos =-1 ; +struct bpf_prog_list *pl; +struct cgroup *p = cgrp; + +/* count effective programs to find where the preorder region ends */ +do { +if (cnt ==0 || (p->bpf.flags[atype] &BPF_F_ALLOW_MULTI )) + cnt +=prog_list_length (&p->bpf.progs[atype], &preorder_cnt); + p =cgroup_parent (p); + }while (p); + +/* replay compute_effective_progs() placement and record target's slot */ + cnt =0 ; + p = cgrp; + fstart = preorder_cnt; + bstart = preorder_cnt -1 ; +do { +if (cnt >0 && !(p->bpf.flags[atype] &BPF_F_ALLOW_MULTI )) +continue ; + + init_bstart = bstart; +hlist_for_each_entry (pl, &p->bpf.progs[atype], node) { +if (!prog_list_prog (pl)) +continue ; + +if (pl->flags &BPF_F_PREORDER ) { +if (pl == target_pl) + pos = bstart; + bstart--; + }else { +if (pl == target_pl) + pos = fstart; + fstart++; + } + cnt++; + } + +/* reverse pre-ordering progs at this cgroup level */ +if (pos >= bstart +1 && pos <= init_bstart) + pos = bstart +1 + init_bstart - pos; + }while ((p =cgroup_parent (p))); + +return pos; +} +/* Swap updated BPF program for given link in effective program arrays across * all descendant cgroups. This function is guaranteed to succeed. */ static void replace_effective_prog (struct cgroup *cgrp,enum cgroup_bpf_attach_type atype, -struct bpf_cgroup_link *link) +struct bpf_prog_list *pl) {struct bpf_prog_array_item *item;struct cgroup_subsys_state *css;struct bpf_prog_array *progs; -struct bpf_prog_list *pl; -struct hlist_head *head; -struct cgroup *cg;int pos;css_for_each_descendant_pre (css, &cgrp->self) {
@@ -790,27 +836,15 @@ static void replace_effective_prog(struct cgroup *cgrp,if (percpu_ref_is_zero (&desc->bpf.refcnt))continue ; -/* find position of link in effective progs array */ -for (pos =0 , cg = desc; cg; cg =cgroup_parent (cg)) { -if (pos && !(cg->bpf.flags[atype] &BPF_F_ALLOW_MULTI )) -continue ; + pos =effective_prog_pos (desc, atype, pl); +if (WARN_ON_ONCE (pos <0 )) +continue ; - head = &cg->bpf.progs[atype]; -hlist_for_each_entry (pl, head, node) { -if (!prog_list_prog (pl)) -continue ; -if (pl->link == link) - goto found; - pos++; - } - } -found: -BUG_ON (!cg); progs =rcu_dereference_protected ( desc->bpf.effective[atype],lockdep_is_held (&cgroup_mutex)); item = &progs->items[pos]; -WRITE_ONCE (item->prog, link->link.prog); +WRITE_ONCE (item->prog, pl->link->link.prog); } }
@@ -853,7 +887,7 @@ static int __cgroup_bpf_replace(struct cgroup *cgrp,return -ENOENT ; old_prog =xchg (&link->link.prog, new_prog); -replace_effective_prog (cgrp, atype, link); +replace_effective_prog (cgrp, atype, pl);bpf_prog_put (old_prog);return 0 ; }
@@ -920,19 +954,14 @@ static struct bpf_prog_list *find_detach_entry(struct hlist_head *progs,* recomputing the array in place. * * @cgrp: The cgroup which descendants to travers -* @prog: A program to detach or NULL -* @link: A link to detach or NULL +* @pl: The prog_list entry being detached * @atype: Type of detach operation */ -static void purge_effective_progs (struct cgroup *cgrp,struct bpf_prog *prog, -struct bpf_cgroup_link *link, +static void purge_effective_progs (struct cgroup *cgrp,struct bpf_prog_list *pl,enum cgroup_bpf_attach_type atype) {struct cgroup_subsys_state *css;struct bpf_prog_array *progs; -struct bpf_prog_list *pl; -struct hlist_head *head; -struct cgroup *cg;int pos;/* recompute effective prog array in place */
@@ -942,24 +971,11 @@ static void purge_effective_progs(struct cgroup *cgrp, struct bpf_prog *prog,if (percpu_ref_is_zero (&desc->bpf.refcnt))continue ; -/* find position of link or prog in effective progs array */ -for (pos =0 , cg = desc; cg; cg =cgroup_parent (cg)) { -if (pos && !(cg->bpf.flags[atype] &BPF_F_ALLOW_MULTI )) -continue ; - - head = &cg->bpf.progs[atype]; -hlist_for_each_entry (pl, head, node) { -if (!prog_list_prog (pl)) -continue ; -if (pl->prog == prog && pl->link == link) - goto found; - pos++; - } - } - + pos =effective_prog_pos (desc, atype, pl);/* no link or prog match, skip the cgroup of this layer */ -continue ; -found: +if (pos <0 ) +continue ; + progs =rcu_dereference_protected ( desc->bpf.effective[atype],lockdep_is_held (&cgroup_mutex));
@@ -1020,7 +1036,7 @@ static int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,/* if update effective array failed replace the prog with a dummy prog*/ pl->prog = old_prog; pl->link = link; -purge_effective_progs (cgrp, old_prog, link, atype); +purge_effective_progs (cgrp, pl, atype); }/* now can actually delete it from this cgroup list */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 622/1276 power: sequencing: fix ABBA deadlock in pwrseq_device_unregister()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit 2d5a7d406ecece5837af1e278ffbbf6c0315560a ]
The pwrseq core takes three locks in consistent order everywhere:
pwrseq_sem -> pwrseq->rw_lock -> pwrseq->state_lock
pwrseq_get() -> pwrseq_match_device() takes pwrseq_sem for reading, then rw_lock for reading. pwrseq_power_on()/pwrseq_power_off() take rw_lock for reading and then state_lock.
pwrseq_device_unregister() is the only exception, it takes: state_lock, then rw_lock for writing and finally pwrseq_sem for writing. This created two potential ABBA deadlock situations that sashiko pointed out.
- pwrseq_power_on/off() take rw_lock for reading then state_lock, while pwrseq_unregister() takes state_lock then rw_lock for writing
- pwrseq_get() takes pwrseq_sem for reading then rw_lock for reading, while pwrseq_unregister() takes rw_lock for writing then pwrseq_sem for writing
Reorder the unregister path to taking pwrseq_sem for writing -> rw_lock for writing and drop the state_lock entirely. This is safe as enable_count is only ever written under rw_lock held for read (via pwrseq_unit_enable()/disable(), reached only from pwrseq_power_on/off()), so holding rw_lock for writing already excludes every other writer and reader and the active-users WARN() stays race-free without state_lock.
--- drivers/power/sequencing/core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/power/sequencing/core.c +6 -3
@@ -543,15 +543,18 @@ void pwrseq_device_unregister(struct pwrseq_device *pwrseq)struct device *dev = &pwrseq->dev;struct pwrseq_target *target; - scoped_guard(mutex, &pwrseq->state_lock) { + scoped_guard(rwsem_write, &pwrseq_sem) {guard (rwsem_write)(&pwrseq->rw_lock); +/* +* Holding rw_lock for write excludes all power on/off callers +* (they hold it for read), so it's safe to read enable_count +* here without taking the state_lock. +*/ list_for_each_entry (target, &pwrseq->targets, list)WARN (target->unit->enable_count,"REMOVING POWER SEQUENCER WITH ACTIVE USERS\n" ); -guard (rwsem_write)(&pwrseq_sem); -device_del (dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 623/1276 drm/edid: fix OOB read in drm_parse_tiled_block()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit faaa1e1155833e7d4ce7e3cfaf64c0d636b190db ]
drm_parse_tiled_block() casts the DisplayID block to a struct displayid_tiled_block and reads the full fixed layout up to tile->topology_id[7] without checking block->num_bytes. The DisplayID iterator only validates the declared payload length, so a crafted EDID can advertise a tiled-display block (tag DATA_BLOCK_TILED_DISPLAY, or DATA_BLOCK_2_TILED_DISPLAY_TOPOLOGY for v2.0) with a small num_bytes at the end of a DisplayID extension. The read then runs past the end of the exact-sized kmemdup()'d EDID allocation, a heap out-of-bounds read.
Reject blocks shorter than the spec's 22-byte tiled payload before reading the fixed struct, as drm_parse_vesa_mso_data() already does.
BUG: KASAN: slab-out-of-bounds in drm_edid_connector_update Read of size 2 at addr ffff888010077700 by task exploit/147 dump_stack_lvl (lib/dump_stack.c:94 ...) print_report (mm/kasan/report.c:378 ...) kasan_report (mm/kasan/report.c:595) drm_edid_connector_update (drivers/gpu/drm/drm_edid.c:7581) bochs_connector_helper_get_modes (drivers/gpu/drm/tiny/bochs.c:574) drm_helper_probe_single_connector_modes (drivers/gpu/drm/drm_probe_helper.c:426) status_store (drivers/gpu/drm/drm_sysfs.c:219) ... vfs_write (fs/read_write.c:595 fs/read_write.c:688) ksys_write (fs/read_write.c:740)
--- drivers/gpu/drm/drm_edid.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/drm_edid.c +8 -0
@@ -7421,6 +7421,14 @@ static void drm_parse_tiled_block(struct drm_connector *connector,u8 num_v_tile, num_h_tile;struct drm_tile_group *tg; +/* tiled block payload per spec: cap 1 + topo 3 + size 4 + bezel 5 + id 9 = 22 */ +if (block->num_bytes <22 ) { +drm_dbg_kms (connector->dev, +"[CONNECTOR:%d:%s] Unexpected tiled block size %u\n" , + connector->base.id, connector->name, block->num_bytes); +return ; + } + w = tile->tile_size[0 ] | tile->tile_size[1 ] <<8 ; h = tile->tile_size[2 ] | tile->tile_size[3 ] <<8 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 624/1276 PCI: endpoint: pci-epf-vntb: Add check to detect db_count value of 0
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit 33bd1ea748bc897c4d13437284e08c658e8d1340 ]
epf_ntb->db_count value should be within 1 to MAX_DB_COUNT. Current code only checks for the upper bound, while the lower bound is unchecked. This can cause a lot of issues in the driver if the user passes 'db_count' as 0.
Add a check for 0 also. While at it, remove the redundant 'db_count' assignment.
--- drivers/pci/endpoint/functions/pci-epf-vntb.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/pci/endpoint/functions/pci-epf-vntb.c +3 -6
@@ -484,7 +484,6 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb) {const struct pci_epc_features *epc_features;struct device *dev; -u32 db_count;int ret; dev = &ntb->epf->dev;
@@ -496,14 +495,12 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb)return -EINVAL ; } - db_count = ntb->db_count; -if (db_count >MAX_DB_COUNT ) { -dev_err (dev,"DB count cannot be more than %d\n" ,MAX_DB_COUNT ); +if (!ntb->db_count || ntb->db_count >MAX_DB_COUNT ) { +dev_err (dev,"DB count %d out of range (1 - %d)\n" , + ntb->db_count,MAX_DB_COUNT );return -EINVAL ; } - ntb->db_count = db_count; -if (epc_features->msi_capable) { ret = pci_epc_set_msi(ntb->epf->epc, ntb->epf->func_no,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 625/1276 PCI: endpoint: pci-epf-ntb: Add check to detect db_count value of 0
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit d1db6d7c2485ee475a04d8354fbb5b26ea10d978 ]
epf_ntb->db_count value should be within 1 to MAX_DB_COUNT. Current code only checks for the upper bound, while the lower bound is unchecked. This can cause a lot of issues in the driver if the user passes 'db_count' as 0.
Add a check for 0 also. While at it, remove the redundant 'db_count' variable from epf_ntb_configure_interrupt().
--- drivers/pci/endpoint/functions/pci-epf-ntb.c | 21 ++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/pci/endpoint/functions/pci-epf-ntb.c +11 -10
@@ -559,12 +559,15 @@ static int epf_ntb_configure_db(struct epf_ntb *ntb,struct pci_epc *epc;int ret; -if (db_count >MAX_DB_COUNT ) -return -EINVAL ; - ntb_epc = ntb->epc[type]; epc = ntb_epc->epc; +if (!db_count || db_count >MAX_DB_COUNT ) { +dev_err (&epc->dev,"DB count %d out of range (1 - %d)\n" , + db_count,MAX_DB_COUNT ); +return -EINVAL ; + } +if (msix) ret =epf_ntb_configure_msix (ntb, type, db_count);else
@@ -1278,7 +1281,6 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb,u8 func_no, vfunc_no;struct pci_epc *epc;struct device *dev; -u32 db_count;int ret; ntb_epc = ntb->epc[type];
@@ -1296,17 +1298,16 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb, func_no = ntb_epc->func_no; vfunc_no = ntb_epc->vfunc_no; - db_count = ntb->db_count; -if (db_count >MAX_DB_COUNT ) { -dev_err (dev,"DB count cannot be more than %d\n" ,MAX_DB_COUNT ); +if (!ntb->db_count || ntb->db_count >MAX_DB_COUNT ) { +dev_err (dev,"DB count %d out of range (1 - %d)\n" , + ntb->db_count,MAX_DB_COUNT );return -EINVAL ; } - ntb->db_count = db_count; epc = ntb_epc->epc;if (msi_capable) { - ret =pci_epc_set_msi (epc, func_no, vfunc_no, db_count); + ret =pci_epc_set_msi (epc, func_no, vfunc_no, ntb->db_count);if (ret) {dev_err (dev,"%s intf: MSI configuration failed\n" ,pci_epc_interface_string (type));
@@ -1315,7 +1316,7 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb, }if (msix_capable) { - ret =pci_epc_set_msix (epc, func_no, vfunc_no, db_count, + ret =pci_epc_set_msix (epc, func_no, vfunc_no, ntb->db_count, ntb_epc->msix_bar, ntb_epc->msix_table_offset);if (ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 626/1276 ice: fix FDIR CTRL VSI resource leak in ice_reset_all_vfs()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dawid Osuchowski <[email protected]>
[ Upstream commit ebbe8868cf473f698e0fbaf436d2618b2bcda806 ]
Resetting all VFs causes resource leak on VFs with FDIR filters enabled as CTRL VSIs are only invalidated and not freed. Fix by using ice_vf_ctrl_vsi_release() instead of ice_vf_ctrl_invalidate_vsi() which aligns behavior with the ice_reset_vf() function.
Reproduction:
echo 1 > /sys/class/net/$pf/device/sriov_numvfs ethtool -N $vf flow-type ether proto 0x9000 action 0 echo 1 > /sys/class/net/$pf/device/reset
--- drivers/net/ethernet/intel/ice/ice_vf_lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_vf_lib.c +1 -1
@@ -800,7 +800,7 @@ void ice_reset_all_vfs(struct ice_pf *pf)* setup only when VF creates its first FDIR rule. */ if (vf->ctrl_vsi_idx !=ICE_NO_VSI ) -ice_vf_ctrl_invalidate_vsi (vf); +ice_vf_ctrl_vsi_release (vf);ice_vf_pre_vsi_rebuild (vf);if (ice_vf_rebuild_vsi (vf)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 627/1276 ice: fix AQ error code comparison in ice_set_pauseparam()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukasz Czapnik <[email protected]>
[ Upstream commit 2bf7744bc3221a63b95c76c94eab1dad832fa401 ]
Fix unreachable code: the conditionals in ice_set_pauseparam() used the bitwise-AND operator suggesting aq_failures is a bitmap, but it is actually an enum, making the third condition logically unreachable.
Replace the if-else ladder with a switch statement. Also move the aq_failures initialization to the variable declaration and remove the redundant zeroing from ice_set_fc().
--- drivers/net/ethernet/intel/ice/ice_common.c | 1 - drivers/net/ethernet/intel/ice/ice_ethtool.c | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/ice/ice_common.c +0 -1
@@ -3623,7 +3623,6 @@ ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool ena_auto_link_update)if (!pi || !aq_failures)return -EINVAL ; - *aq_failures =0 ; hw = pi->hw; pcaps =kzalloc (sizeof (*pcaps),GFP_KERNEL );
drivers/net/ethernet/intel/ice/ice_ethtool.c +8 -4
@@ -3499,7 +3499,7 @@ ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)struct ice_vsi *vsi = np->vsi;struct ice_hw *hw = &pf->hw;struct ice_port_info *pi; -u8 aq_failures; +u8 aq_failures =0 ;bool link_up;u32 is_an;int err;
@@ -3570,18 +3570,22 @@ ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)/* Set the FC mode and only restart AN if link is up */ err =ice_set_fc (pi, &aq_failures, link_up); -if (aq_failures &ICE_SET_FC_AQ_FAIL_GET ) { +switch (aq_failures) { +case ICE_SET_FC_AQ_FAIL_GET :netdev_info (netdev,"Set fc failed on the get_phy_capabilities call with err %d aq_err %s\n" , err,ice_aq_str (hw->adminq.sq_last_status)); err = -EAGAIN ; - }else if (aq_failures &ICE_SET_FC_AQ_FAIL_SET ) { +break ; +case ICE_SET_FC_AQ_FAIL_SET :netdev_info (netdev,"Set fc failed on the set_phy_config call with err %d aq_err %s\n" , err,ice_aq_str (hw->adminq.sq_last_status)); err = -EAGAIN ; - }else if (aq_failures &ICE_SET_FC_AQ_FAIL_UPDATE ) { +break ; +case ICE_SET_FC_AQ_FAIL_UPDATE :netdev_info (netdev,"Set fc failed on the get_link_info call with err %d aq_err %s\n" , err,ice_aq_str (hw->adminq.sq_last_status)); err = -EAGAIN ; +break ; }return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 628/1276 ice: call netif_keep_dst() once when entering switchdev mode
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marcin Szycik <[email protected]>
[ Upstream commit c0d00c882bc432990d57052a659f9a8bd1f60687 ]
netif_keep_dst() only needs to be called once for the uplink VSI, not once for each port representor. Move it from ice_eswitch_setup_repr() to ice_eswitch_enable_switchdev().
--- drivers/net/ethernet/intel/ice/ice_eswitch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_eswitch.c +2 -2
@@ -116,8 +116,6 @@ static int ice_eswitch_setup_repr(struct ice_pf *pf, struct ice_repr *repr)if (!repr->dst)return -ENOMEM ; -netif_keep_dst (uplink_vsi->netdev); - dst = repr->dst; dst->u.port_info.port_id = vsi->vsi_num; dst->u.port_info.lower_dev = uplink_vsi->netdev;
@@ -306,6 +304,8 @@ static int ice_eswitch_enable_switchdev(struct ice_pf *pf)if (ice_eswitch_br_offloads_init (pf)) goto err_br_offloads; +netif_keep_dst (uplink_vsi->netdev); + pf->eswitch.is_running = true;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 629/1276 ice: dpll: set pointers to NULL after kfree in ice_dpll_deinit_info
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: ZhaoJinming <[email protected]>
[ Upstream commit a903afff66d7379c6ece42bd18b2a17f4c79d1a9 ]
ice_dpll_deinit_info() calls kfree() on several pf->dplls fields (inputs, outputs, eec.input_prio, pps.input_prio) but does not set the pointers to NULL afterward. This leaves dangling pointers in the pf->dplls structure.
While not currently exploitable through existing code paths, this is unsafe because:
1. If ice_dpll_init_info() is called again after a deinit (e.g. during driver recovery), and a subsequent allocation within init fails, the error path will jump to deinit_info and call ice_dpll_deinit_info() again. Since some pointers still hold the old freed addresses, this would result in a double-free.
2. Any future code that checks these pointers before use or after free would be unprotected against use-after-free.
Follow the common kernel convention of setting pointers to NULL after kfree() so that:
- kfree(NULL) is a safe no-op, preventing double-free
- NULL checks on these pointers become meaningful
This is a preparatory fix for a subsequent patch that routes additional error paths in ice_dpll_init_info() to the deinit_info label.
--- drivers/net/ethernet/intel/ice/ice_dpll.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/intel/ice/ice_dpll.c +4 -0
@@ -2279,9 +2279,13 @@ ice_dpll_init_pins_info(struct ice_pf *pf, enum ice_dpll_pin_type pin_type)static void ice_dpll_deinit_info (struct ice_pf *pf) {kfree (pf->dplls.inputs); + pf->dplls.inputs =NULL ;kfree (pf->dplls.outputs); + pf->dplls.outputs =NULL ;kfree (pf->dplls.eec.input_prio); + pf->dplls.eec.input_prio =NULL ;kfree (pf->dplls.pps.input_prio); + pf->dplls.pps.input_prio =NULL ; }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 630/1276 ice: dpll: fix memory leak in ice_dpll_init_info error paths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: ZhaoJinming <[email protected]>
[ Upstream commit 20da495f2df0fd4adc435d3d621366e8c807539c ]
Several error return paths in ice_dpll_init_info() directly return without freeing previously allocated resources, causing memory leaks:
- When de->input_prio allocation fails, d->inputs is leaked
- When dp->input_prio allocation fails, d->inputs and de->input_prio are leaked
- When ice_get_cgu_rclk_pin_info() fails, all previously allocated inputs/outputs/input_prio are leaked
- When ice_dpll_init_pins_info(RCLK_INPUT) fails, same resources are leaked
Fix this by jumping to the deinit_info label which properly calls ice_dpll_deinit_info() to free all allocated resources.
--- drivers/net/ethernet/intel/ice/ice_dpll.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/ice/ice_dpll.c +10 -6
@@ -2333,12 +2333,16 @@ static int ice_dpll_init_info(struct ice_pf *pf, bool cgu) alloc_size =sizeof (*de->input_prio) * d->num_inputs; de->input_prio =kzalloc (alloc_size,GFP_KERNEL ); -if (!de->input_prio) -return -ENOMEM ; +if (!de->input_prio) { + ret = -ENOMEM ; + goto deinit_info; + } dp->input_prio =kzalloc (alloc_size,GFP_KERNEL ); -if (!dp->input_prio) -return -ENOMEM ; +if (!dp->input_prio) { + ret = -ENOMEM ; + goto deinit_info; + } ret =ice_dpll_init_pins_info (pf,ICE_DPLL_PIN_TYPE_INPUT );if (ret)
@@ -2360,12 +2364,12 @@ static int ice_dpll_init_info(struct ice_pf *pf, bool cgu) ret =ice_get_cgu_rclk_pin_info (&pf->hw, &d->base_rclk_idx, &pf->dplls.rclk.num_parents);if (ret) -return ret; + goto deinit_info;for (i =0 ; i < pf->dplls.rclk.num_parents; i++) pf->dplls.rclk.parent_idx[i] = d->base_rclk_idx + i; ret =ice_dpll_init_pins_info (pf,ICE_DPLL_PIN_TYPE_RCLK_INPUT );if (ret) -return ret; + goto deinit_info; de->mode =DPLL_MODE_AUTOMATIC ; dp->mode =DPLL_MODE_AUTOMATIC ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 631/1276 i40e: Fix i40e_debug() to use struct i40e_hw argument
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mohamed Khalfella <[email protected]>
[ Upstream commit 798f94603eb0737033861efd320a9159f382a7c5 ]
i40e_debug() macro takes struct i40e_hw *h as first argument. But the macro body uses hw instead of h. This has been working so far because hw happens to be the name of the variable in the context where the macro is expanded. Fix the macro to use the passed argument.
--- drivers/net/ethernet/intel/i40e/i40e_debug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/i40e/i40e_debug.h +1 -1
@@ -42,7 +42,7 @@ struct device *i40e_hw_to_dev(struct i40e_hw *hw);#define i40e_debug (h, m, s, ...) \ do { \ if (((m) & (h)->debug_mask)) \ - dev_info(i40e_hw_to_dev(hw), s, ##__VA_ARGS__); \ + dev_info(i40e_hw_to_dev(h), s, ##__VA_ARGS__); \ } while (0)#endif /* _I40E_DEBUG_H_ */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 632/1276 rtc: msc313: fix NULL deref in shared IRQ handler at probe
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stepan Ionichev <[email protected]>
[ Upstream commit a369f48be8de426a7d2bca18dbd46c2ad1138803 ]
msc313_rtc_probe() calls devm_request_irq() with IRQF_SHARED and &pdev->dev as the cookie, but platform_set_drvdata() is only called later after the clock setup. With a shared IRQ line, another device on the same line can trigger the handler in that window. The handler does dev_get_drvdata() on the cookie, gets NULL, and dereferences priv->rtc_base in interrupt context.
Pass priv as the cookie directly so the handler reads it from dev_id without the lookup, removing the dependency on probe order.
--- drivers/rtc/rtc-msc313.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-msc313.c +2 -2
@@ -160,7 +160,7 @@ static const struct rtc_class_ops msc313_rtc_ops = {static irqreturn_t msc313_rtc_interrupt (s32 irq,void *dev_id) { -struct msc313_rtc *priv =dev_get_drvdata (dev_id); +struct msc313_rtc *priv = dev_id;u16 reg; reg =readw (priv->rtc_base +REG_RTC_STATUS_INT );
@@ -206,7 +206,7 @@ static int msc313_rtc_probe(struct platform_device *pdev) priv->rtc_dev->range_max =U32_MAX ; ret =devm_request_irq (dev, irq, msc313_rtc_interrupt,IRQF_SHARED , -dev_name (&pdev->dev), &pdev->dev); +dev_name (&pdev->dev), priv);if (ret) {dev_err (dev,"Could not request IRQ\n" );return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 633/1276 ksmbd: fix use-after-free of conn->preauth_info in concurrent SMB2 NEGOTIATE
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gil Portnoy <[email protected]>
[ Upstream commit 0c054227479ed7e36ebccb3a558bc0ef698264f6 ]
conn->preauth_info is shared connection state (struct preauth_integrity_info, kmalloc-96) that is allocated and freed by the SMB2 NEGOTIATE handler and read by the response send path.
smb2_handle_negotiate() allocates conn->preauth_info, and on a deassemble_neg_contexts() failure kfrees it and sets it to NULL. Both the allocation and the free/NULL happen under ksmbd_conn_lock(conn) (the connection srv_mutex), which is held across the whole handler body.
The response send path smb3_preauth_hash_rsp(), called from the send:
block of __handle_ksmbd_work(), reads conn->preauth_info and dereferences conn->preauth_info->Preauth_HashValue (via ksmbd_gen_preauth_integrity_hash()) without taking conn_lock. When a client drives two SMB2 NEGOTIATE requests on the same connection, one worker can free conn->preauth_info on the failing-negotiate path while a concurrent send-path worker is reading it, producing a slab use-after-free read (KASAN-confirmed).
The send-path read tested conn->preauth_info for NULL but raced with the free that occurs between the NULL check and the dereference, so the NULL guard alone does not close the window.
Serialize the NEGOTIATE-branch read in smb3_preauth_hash_rsp() under ksmbd_conn_lock(conn) and re-check conn->preauth_info inside the lock. Because the negotiate handler holds conn_lock across its kfree + NULL assignment, a reader that also takes conn_lock either runs fully before the allocation or fully after the NULL store, and can never observe the freed-but-not-yet-NULLed pointer. ksmbd_gen_preauth_integrity_hash() takes no locks itself (it only computes a SHA-512 over the buffer), so no lock-ordering inversion is introduced, and conn_lock is a sleepable mutex which is safe on this send path (it already performs network I/O).
--- fs/smb/server/smb2pdu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
fs/smb/server/smb2pdu.c +7 -4
@@ -9142,10 +9142,13 @@ void smb3_preauth_hash_rsp(struct ksmbd_work *work)WORK_BUFFERS (work, req, rsp); -if (le16_to_cpu (req->Command) ==SMB2_NEGOTIATE_HE && - conn->preauth_info) -ksmbd_gen_preauth_integrity_hash (conn, work->response_buf, - conn->preauth_info->Preauth_HashValue); +if (le16_to_cpu (req->Command) ==SMB2_NEGOTIATE_HE ) { +ksmbd_conn_lock (conn); +if (conn->preauth_info) +ksmbd_gen_preauth_integrity_hash (conn, work->response_buf, + conn->preauth_info->Preauth_HashValue); +ksmbd_conn_unlock (conn); + }if (le16_to_cpu (rsp->Command) ==SMB2_SESSION_SETUP_HE && sess) {__u8 *hash_value;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 634/1276 ipv6: Fix null-ptr-deref in fib6_nh_mtu_change().
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 46c3b8191aad3d032776bf3bebf03efdf5f4b905 ]
fib6_nh_mtu_change() re-fetches idev via __in6_dev_get(arg->dev) and dereferences idev->cnf.mtu6 without a NULL check. addrconf_ifdown() clears dev->ip6_ptr with RCU_INIT_POINTER() after rt6_disable_ip() has released tb6_lock, so the RA-driven MTU walk can observe a NULL idev and oops. The caller rt6_mtu_change_route() guards its own __in6_dev_get(), but this re-fetch is unguarded; nexthop-backed routes survive addrconf_ifdown()'s flush, so the walk still reaches it after ip6_ptr is nulled.
Return 0 when idev is NULL, matching rt6_mtu_change_route() and the fib6_mtu() fix in commit 5ad509c1fdad ("ipv6: Fix null-ptr-deref in fib6_mtu().").
Oops: general protection fault, ... KASAN: null-ptr-deref in range
[0x00000000000002a8-0x00000000000002af]
RIP: 0010:fib6_nh_mtu_change+0x203/0x990
rt6_mtu_change_route+0x141/0x1d0
__fib6_clean_all+0xd0/0x160
rt6_mtu_change+0xb4/0x100
ndisc_router_discovery+0x24b5/0x2cb0
icmpv6_rcv+0x12e9/0x1710
ipv6_rcv+0x39b/0x410--- net/ipv6/route.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv6/route.c +3 -0
@@ -4992,6 +4992,9 @@ static int fib6_nh_mtu_change(struct fib6_nh *nh, void *_arg)struct inet6_dev *idev =__in6_dev_get (arg->dev);u32 mtu = f6i->fib6_pmtu; +if (!idev) +return 0 ; +if (mtu >= arg->mtu || (mtu < arg->mtu && mtu == idev->cnf.mtu6))fib6_metric_set (f6i,RTAX_MTU , arg->mtu);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 635/1276 net: bnxt: use ethtool string helpers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 9b4b2e02c1e19e6a983cf1b3f082315239d38cb0 ]
Avoids having to use manual pointer manipulation.
Stable-dep-of: 40529e58629b ("eth: bnxt: improve the timing of stats")
--- .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 115 ++++++++---------- 1 file changed, 54 insertions(+), 61 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +54 -61
@@ -705,112 +705,105 @@ static void bnxt_get_ethtool_stats(struct net_device *dev,static void bnxt_get_strings (struct net_device *dev,u32 stringset,u8 *buf) {struct bnxt *bp =netdev_priv (dev); -static const char *const *str;u32 i, j, num_str; +const char *str;switch (stringset) {case ETH_SS_STATS :for (i =0 ; i < bp->cp_nr_rings; i++) { -if (is_rx_ring (bp, i)) { - num_str =NUM_RING_RX_HW_STATS ; -for (j =0 ; j < num_str; j++) { -sprintf (buf,"[%d]: %s" , i, - bnxt_ring_rx_stats_str[j]); - buf +=ETH_GSTRING_LEN ; +if (is_rx_ring (bp, i)) +for (j =0 ; j <NUM_RING_RX_HW_STATS ; j++) { + str = bnxt_ring_rx_stats_str[j]; +ethtool_sprintf (&buf,"[%d]: %s" , i, + str); } - } -if (is_tx_ring (bp, i)) { - num_str =NUM_RING_TX_HW_STATS ; -for (j =0 ; j < num_str; j++) { -sprintf (buf,"[%d]: %s" , i, - bnxt_ring_tx_stats_str[j]); - buf +=ETH_GSTRING_LEN ; +if (is_tx_ring (bp, i)) +for (j =0 ; j <NUM_RING_TX_HW_STATS ; j++) { + str = bnxt_ring_tx_stats_str[j]; +ethtool_sprintf (&buf,"[%d]: %s" , i, + str); } - } num_str =bnxt_get_num_tpa_ring_stats (bp);if (!num_str || !is_rx_ring (bp, i)) goto skip_tpa_stats;if (bp->max_tpa_v2) - str = bnxt_ring_tpa2_stats_str; +for (j =0 ; j < num_str; j++) { + str = bnxt_ring_tpa2_stats_str[j]; +ethtool_sprintf (&buf,"[%d]: %s" , i, + str); + }else - str = bnxt_ring_tpa_stats_str; - -for (j =0 ; j < num_str; j++) { -sprintf (buf,"[%d]: %s" , i, str[j]); - buf +=ETH_GSTRING_LEN ; - } -skip_tpa_stats: -if (is_rx_ring (bp, i)) { - num_str =NUM_RING_RX_SW_STATS ;for (j =0 ; j < num_str; j++) { -sprintf (buf,"[%d]: %s" , i, - bnxt_rx_sw_stats_str[j]); - buf +=ETH_GSTRING_LEN ; + str = bnxt_ring_tpa_stats_str[j]; +ethtool_sprintf (&buf,"[%d]: %s" , i, + str); } +skip_tpa_stats: +if (is_rx_ring (bp, i)) +for (j =0 ; j <NUM_RING_RX_SW_STATS ; j++) { + str = bnxt_rx_sw_stats_str[j]; +ethtool_sprintf (&buf,"[%d]: %s" , i, + str); + } +for (j =0 ; j <NUM_RING_CMN_SW_STATS ; j++) { + str = bnxt_cmn_sw_stats_str[j]; +ethtool_sprintf (&buf,"[%d]: %s" , i, str); } - num_str =NUM_RING_CMN_SW_STATS ; -for (j =0 ; j < num_str; j++) { -sprintf (buf,"[%d]: %s" , i, - bnxt_cmn_sw_stats_str[j]); - buf +=ETH_GSTRING_LEN ; - } - } -for (i =0 ; i <BNXT_NUM_RING_ERR_STATS ; i++) { -strscpy (buf, bnxt_ring_err_stats_arr[i],ETH_GSTRING_LEN ); - buf +=ETH_GSTRING_LEN ; } +for (i =0 ; i <BNXT_NUM_RING_ERR_STATS ; i++) +ethtool_puts (&buf, bnxt_ring_err_stats_arr[i]); -if (bp->flags &BNXT_FLAG_PORT_STATS ) { +if (bp->flags &BNXT_FLAG_PORT_STATS )for (i =0 ; i <BNXT_NUM_PORT_STATS ; i++) { -strcpy (buf, bnxt_port_stats_arr[i].string); - buf +=ETH_GSTRING_LEN ; + str = bnxt_port_stats_arr[i].string; +ethtool_puts (&buf, str); } - } +if (bp->flags &BNXT_FLAG_PORT_STATS_EXT ) {u32 len; len =min_t (u32, bp->fw_rx_stats_ext_size,ARRAY_SIZE (bnxt_port_stats_ext_arr));for (i =0 ; i < len; i++) { -strcpy (buf, bnxt_port_stats_ext_arr[i].string); - buf +=ETH_GSTRING_LEN ; + str = bnxt_port_stats_ext_arr[i].string; +ethtool_puts (&buf, str); } + len =min_t (u32, bp->fw_tx_stats_ext_size,ARRAY_SIZE (bnxt_tx_port_stats_ext_arr));for (i =0 ; i < len; i++) { -strcpy (buf, - bnxt_tx_port_stats_ext_arr[i].string); - buf +=ETH_GSTRING_LEN ; + str = bnxt_tx_port_stats_ext_arr[i].string; +ethtool_puts (&buf, str); } +if (bp->pri2cos_valid) {for (i =0 ; i <8 ; i++) { -strcpy (buf, - bnxt_rx_bytes_pri_arr[i].string); - buf +=ETH_GSTRING_LEN ; + str = bnxt_rx_bytes_pri_arr[i].string; +ethtool_puts (&buf, str); } +for (i =0 ; i <8 ; i++) { -strcpy (buf, - bnxt_rx_pkts_pri_arr[i].string); - buf +=ETH_GSTRING_LEN ; + str = bnxt_rx_pkts_pri_arr[i].string; +ethtool_puts (&buf, str); } +for (i =0 ; i <8 ; i++) { -strcpy (buf, - bnxt_tx_bytes_pri_arr[i].string); - buf +=ETH_GSTRING_LEN ; + str = bnxt_tx_bytes_pri_arr[i].string; +ethtool_puts (&buf, str); } +for (i =0 ; i <8 ; i++) { -strcpy (buf, - bnxt_tx_pkts_pri_arr[i].string); - buf +=ETH_GSTRING_LEN ; + str = bnxt_tx_pkts_pri_arr[i].string; +ethtool_puts (&buf, str); } } }break ;case ETH_SS_TEST :if (bp->num_tests) -memcpy (buf, bp->test_info->string, - bp->num_tests *ETH_GSTRING_LEN ); +for (i =0 ; i < bp->num_tests; i++) +ethtool_puts (&buf, bp->test_info->string[i]);break ;default : netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 636/1276 eth: bnxt: gather and report HW-GRO stats
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit a7fc1a488f09f0fbf727fe3ca5b017e7657f152d ]
Count and report HW-GRO stats as seen by the kernel. The device stats for GRO seem to not reflect the reality, perhaps they count sessions which did not actually result in any aggregation. Also they count wire packets, so we have to count super-frames, anyway.
Stable-dep-of: 40529e58629b ("eth: bnxt: improve the timing of stats")
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 15 +++++++++++++-- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +13 -2
@@ -1733,7 +1733,8 @@ static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp,struct bnxt_tpa_info *tpa_info, struct rx_tpa_end_cmp *tpa_end, struct rx_tpa_end_cmp_ext *tpa_end1, - struct sk_buff *skb) + struct sk_buff *skb, + struct bnxt_rx_sw_stats *rx_stats) { #ifdef CONFIG_INET int payload_off;
@@ -1743,6 +1744,9 @@ static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp,if (segs ==1 )return skb; + rx_stats->rx_hw_gro_packets++; + rx_stats->rx_hw_gro_wire_packets += segs; +NAPI_GRO_CB (skb)->count = segs;skb_shinfo (skb)->gso_size =le32_to_cpu (tpa_end1->rx_tpa_end_cmp_seg_len);
@@ -1915,7 +1919,8 @@ static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp, }if (gro) - skb =bnxt_gro_skb (bp, tpa_info, tpa_end, tpa_end1, skb); + skb =bnxt_gro_skb (bp, tpa_info, tpa_end, tpa_end1, skb, + &cpr->sw_stats->rx);return skb; }
@@ -12816,6 +12821,8 @@ static void bnxt_get_one_ring_err_stats(struct bnxt *bp, stats->rx_total_netpoll_discards += sw_stats->rx.rx_netpoll_discards; stats->rx_total_ring_discards +=BNXT_GET_RING_STATS64 (hw_stats, rx_discard_pkts); + stats->rx_total_hw_gro_packets += sw_stats->rx.rx_hw_gro_packets; + stats->rx_total_hw_gro_wire_packets += sw_stats->rx.rx_hw_gro_wire_packets; stats->tx_total_resets += sw_stats->tx.tx_resets; stats->tx_total_ring_discards +=BNXT_GET_RING_STATS64 (hw_stats, tx_discard_pkts);
@@ -15224,6 +15231,8 @@ static void bnxt_get_queue_stats_rx(struct net_device *dev, int i, stats->bytes +=BNXT_GET_RING_STATS64 (sw, rx_bcast_bytes); stats->alloc_fail = cpr->sw_stats->rx.rx_oom_discards; + stats->hw_gro_packets = cpr->sw_stats->rx.rx_hw_gro_packets; + stats->hw_gro_wire_packets = cpr->sw_stats->rx.rx_hw_gro_wire_packets; } static void bnxt_get_queue_stats_tx(struct net_device *dev, int i,
@@ -15259,6 +15268,8 @@ static void bnxt_get_base_stats(struct net_device *dev, rx->packets = bp->net_stats_prev.rx_packets; rx->bytes = bp->net_stats_prev.rx_bytes; rx->alloc_fail = bp->ring_err_stats_prev.rx_total_oom_discards; + rx->hw_gro_packets = bp->ring_err_stats_prev.rx_total_hw_gro_packets; + rx->hw_gro_wire_packets = bp->ring_err_stats_prev.rx_total_hw_gro_wire_packets; tx->packets = bp->net_stats_prev.tx_packets; tx->bytes = bp->net_stats_prev.tx_bytes;
drivers/net/ethernet/broadcom/bnxt/bnxt.h +6 -0
@@ -1113,8 +1113,11 @@ struct bnxt_rx_sw_stats {u64 rx_l4_csum_errors;u64 rx_resets;u64 rx_buf_errors; +/* end of ethtool -S stats */ u64 rx_oom_discards;u64 rx_netpoll_discards; +u64 rx_hw_gro_packets; +u64 rx_hw_gro_wire_packets; };struct bnxt_tx_sw_stats {
@@ -1141,6 +1144,9 @@ struct bnxt_total_ring_err_stats {u64 tx_total_resets;u64 tx_total_ring_discards;u64 total_missed_irqs; +/* end of ethtool -S stats */ +u64 rx_total_hw_gro_packets; +u64 rx_total_hw_gro_wire_packets; };struct bnxt_stats_mem {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 637/1276 eth: bnxt: rename ring_err_stats -> ring_drv_stats
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 6c32b07650676ab4c112ff8e9d345b6770ae2be5 ]
We recently added GRO stats to bnxt, which are maintained by the driver. Having "err" in the name of the struct for ring stats no longer makes sense (as pointed out by Michael, see Link).
Rename them to "drv" stats, as these are all maintained by the driver (even if partially based on info from descriptors). Michael suggested calling these misc, happy to go back to that. IMHO "drv" is a bit more meaningful that "misc".
Pure rename using sed, no functional changes.
Stable-dep-of: 40529e58629b ("eth: bnxt: improve the timing of stats")
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 18 ++++++++--------- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 8 ++++---- .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 20 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +9 -9
@@ -12557,7 +12557,7 @@ static void __bnxt_close_nic(struct bnxt *bp, bool irq_re_init,/* Save ring stats before shutdown */ if (bp->bnapi && irq_re_init) {bnxt_get_ring_stats (bp, &bp->net_stats_prev); -bnxt_get_ring_err_stats (bp, &bp->ring_err_stats_prev); +bnxt_get_ring_drv_stats (bp, &bp->ring_drv_stats_prev); }if (irq_re_init) {bnxt_free_irq (bp);
@@ -12807,8 +12807,8 @@ bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)clear_bit (BNXT_STATE_READ_STATS , &bp->state); } -static void bnxt_get_one_ring_err_stats (struct bnxt *bp, -struct bnxt_total_ring_err_stats *stats, +static void bnxt_get_one_ring_drv_stats (struct bnxt *bp, +struct bnxt_total_ring_drv_stats *stats,struct bnxt_cp_ring_info *cpr) {struct bnxt_sw_stats *sw_stats = cpr->sw_stats;
@@ -12829,13 +12829,13 @@ static void bnxt_get_one_ring_err_stats(struct bnxt *bp, stats->total_missed_irqs += sw_stats->cmn.missed_irqs; } -void bnxt_get_ring_err_stats (struct bnxt *bp, -struct bnxt_total_ring_err_stats *stats) +void bnxt_get_ring_drv_stats (struct bnxt *bp, +struct bnxt_total_ring_drv_stats *stats) {int i;for (i =0 ; i < bp->cp_nr_rings; i++) -bnxt_get_one_ring_err_stats (bp, stats, &bp->bnapi[i]->cp_ring); +bnxt_get_one_ring_drv_stats (bp, stats, &bp->bnapi[i]->cp_ring); }static bool bnxt_mc_list_updated (struct bnxt *bp,u32 *rx_mask)
@@ -15267,9 +15267,9 @@ static void bnxt_get_base_stats(struct net_device *dev, rx->packets = bp->net_stats_prev.rx_packets; rx->bytes = bp->net_stats_prev.rx_bytes; - rx->alloc_fail = bp->ring_err_stats_prev.rx_total_oom_discards; - rx->hw_gro_packets = bp->ring_err_stats_prev.rx_total_hw_gro_packets; - rx->hw_gro_wire_packets = bp->ring_err_stats_prev.rx_total_hw_gro_wire_packets; + rx->alloc_fail = bp->ring_drv_stats_prev.rx_total_oom_discards; + rx->hw_gro_packets = bp->ring_drv_stats_prev.rx_total_hw_gro_packets; + rx->hw_gro_wire_packets = bp->ring_drv_stats_prev.rx_total_hw_gro_wire_packets; tx->packets = bp->net_stats_prev.tx_packets; tx->bytes = bp->net_stats_prev.tx_bytes;
drivers/net/ethernet/broadcom/bnxt/bnxt.h +4 -4
@@ -1134,7 +1134,7 @@ struct bnxt_sw_stats {struct bnxt_cmn_sw_stats cmn; }; -struct bnxt_total_ring_err_stats { +struct bnxt_total_ring_drv_stats {u64 rx_total_l4_csum_errors;u64 rx_total_resets;u64 rx_total_buf_errors;
@@ -2479,7 +2479,7 @@ struct bnxt {u8 pri2cos_idx[8 ];u8 pri2cos_valid; -struct bnxt_total_ring_err_stats ring_err_stats_prev; +struct bnxt_total_ring_drv_stats ring_drv_stats_prev;u16 hwrm_max_req_len;u16 hwrm_max_ext_req_len;
@@ -2864,8 +2864,8 @@ int bnxt_half_open_nic(struct bnxt *bp);void bnxt_half_close_nic (struct bnxt *bp);void bnxt_reenable_sriov (struct bnxt *bp);void bnxt_close_nic (struct bnxt *,bool ,bool ); -void bnxt_get_ring_err_stats (struct bnxt *bp, -struct bnxt_total_ring_err_stats *stats); +void bnxt_get_ring_drv_stats (struct bnxt *bp, +struct bnxt_total_ring_drv_stats *stats);bool bnxt_rfs_capable (struct bnxt *bp,bool new_rss_ctx);int bnxt_dbg_hwrm_rd_reg (struct bnxt *bp,u32 reg_off,u16 num_words,u32 *reg_buf);
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +10 -10
@@ -339,7 +339,7 @@ enum { RX_NETPOLL_DISCARDS, }; -static const char *const bnxt_ring_err_stats_arr[] = { +static const char *const bnxt_ring_drv_stats_arr[] = {"rx_total_l4_csum_errors" ,"rx_total_resets" ,"rx_total_buf_errors" ,
@@ -499,7 +499,7 @@ static const struct { BNXT_TX_STATS_PRI_ENTRIES(tx_packets), }; -#define BNXT_NUM_RING_ERR_STATS ARRAY_SIZE(bnxt_ring_err_stats_arr) +#define BNXT_NUM_RING_DRV_STATS ARRAY_SIZE(bnxt_ring_drv_stats_arr)#define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr)#define BNXT_NUM_STATS_PRI \ (ARRAY_SIZE(bnxt_rx_bytes_pri_arr) + \
@@ -538,7 +538,7 @@ static int bnxt_get_num_stats(struct bnxt *bp)int num_stats =bnxt_get_num_ring_stats (bp);int len; - num_stats +=BNXT_NUM_RING_ERR_STATS ; + num_stats +=BNXT_NUM_RING_DRV_STATS ;if (bp->flags &BNXT_FLAG_PORT_STATS ) num_stats +=BNXT_NUM_PORT_STATS ;
@@ -593,7 +593,7 @@ static bool is_tx_ring(struct bnxt *bp, int ring_num)static void bnxt_get_ethtool_stats (struct net_device *dev,struct ethtool_stats *stats,u64 *buf) { -struct bnxt_total_ring_err_stats ring_err_stats = {0 }; +struct bnxt_total_ring_drv_stats ring_drv_stats = {0 };struct bnxt *bp =netdev_priv (dev);u64 *curr, *prev;u32 tpa_stats;
@@ -642,12 +642,12 @@ static void bnxt_get_ethtool_stats(struct net_device *dev, buf[j] = sw[k]; } -bnxt_get_ring_err_stats (bp, &ring_err_stats); +bnxt_get_ring_drv_stats (bp, &ring_drv_stats); skip_ring_stats: - curr = &ring_err_stats.rx_total_l4_csum_errors; - prev = &bp->ring_err_stats_prev.rx_total_l4_csum_errors; -for (i =0 ; i <BNXT_NUM_RING_ERR_STATS ; i++, j++, curr++, prev++) + curr = &ring_drv_stats.rx_total_l4_csum_errors; + prev = &bp->ring_drv_stats_prev.rx_total_l4_csum_errors; +for (i =0 ; i <BNXT_NUM_RING_DRV_STATS ; i++, j++, curr++, prev++) buf[j] = *curr + *prev;if (bp->flags &BNXT_FLAG_PORT_STATS ) {
@@ -751,8 +751,8 @@ static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf)ethtool_sprintf (&buf,"[%d]: %s" , i, str); } } -for (i =0 ; i <BNXT_NUM_RING_ERR_STATS ; i++) -ethtool_puts (&buf, bnxt_ring_err_stats_arr[i]); +for (i =0 ; i <BNXT_NUM_RING_DRV_STATS ; i++) +ethtool_puts (&buf, bnxt_ring_drv_stats_arr[i]);if (bp->flags &BNXT_FLAG_PORT_STATS )for (i =0 ; i <BNXT_NUM_PORT_STATS ; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 638/1276 eth: bnxt: improve the timing of stats
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 40529e58629baa9ce72143cb46cf1b3d2ca0d465 ]
Kernel selftests wait 1.25x of the promised stats refresh time (as read from ethtool -c). bnxt reports 1sec by default, but the stats update process has two steps. First device DMAs the new values, then the service task performs update in full-width SW counters. So the worst case delay is actually 2x.
Note that the behavior is different for ring stats and port stats. Port stats are fetched synchronously by the service worker, so there's no risk of doubling up the delay there.
The problem of stale stats impacts not only tests but real workloads which monitor egress bandwidth of a NIC. The inaccuracy causes double counting in the next cycle and spurious overload alarms.
Try to read from the DMA buffer more aggressively, to mitigate timing issues between DMA and service task. The SW update should be cheap.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 48 ++++++++++++++++++- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 5 ++ .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 1 + 3 files changed, 53 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +47 -1
@@ -9963,7 +9963,7 @@ static void bnxt_accumulate_stats(struct bnxt_stats_mem *stats) stats->hw_masks, stats->len / 8, false); } -static void bnxt_accumulate_all_stats (struct bnxt *bp) +static void bnxt_accumulate_ring_stats (struct bnxt *bp) {struct bnxt_stats_mem *ring0_stats;bool ignore_zero = false;
@@ -9986,6 +9986,10 @@ static void bnxt_accumulate_all_stats(struct bnxt *bp) ring0_stats->hw_masks, ring0_stats->len / 8, ignore_zero); } +} + +static void bnxt_accumulate_port_stats (struct bnxt *bp) +{if (bp->flags &BNXT_FLAG_PORT_STATS ) {struct bnxt_stats_mem *stats = &bp->port_stats;__le64 *hw_stats = stats->hw_stats;
@@ -10008,6 +10012,41 @@ static void bnxt_accumulate_all_stats(struct bnxt *bp) } } +static void bnxt_accumulate_all_stats (struct bnxt *bp) +{ +bnxt_accumulate_ring_stats (bp); +bnxt_accumulate_port_stats (bp); +} + +/* Re-accumulate ring stats from DMA buffers if stale. +* uAPIs for reading sw_stats should call this first. +* +* We promise user space update frequency of bp->stats_coal_ticks but +* the update is a two step process - first device updates the DMA buffer, +* then we have to update from that buffer to driver stats in the service work. +* Worst case we would be 2x off from the desired frequency. +* Sync the stats sooner, if stale. The 20% threshold was chosen arbitrarily. +* +* Ideally we would split the user-configured time into two portions, +* i.e. also lower the DMA period by the 20%. But the DMA timer seems to have +* too coarse granularity to play such tricks. +*/ +void bnxt_sync_ring_stats (struct bnxt *bp) +{ +unsigned long stale; + +if (!netif_running (bp->dev) || !bp->stats_coal_ticks) +return ; + +spin_lock (&bp->stats_lock); + stale =usecs_to_jiffies (bp->stats_coal_ticks /5 ); +if (time_after_eq (jiffies, bp->stats_updated_jiffies + stale)) { +bnxt_accumulate_ring_stats (bp); + bp->stats_updated_jiffies = jiffies; + } +spin_unlock (&bp->stats_lock); +} +static int bnxt_hwrm_port_qstats (struct bnxt *bp,u8 flags) {struct hwrm_port_qstats_input *req;
@@ -12779,6 +12818,7 @@ bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)return ; } +bnxt_sync_ring_stats (bp);bnxt_get_ring_stats (bp, stats);bnxt_add_prev_stats (bp, stats);
@@ -13948,7 +13988,10 @@ static void bnxt_sp_task(struct work_struct *work)if (test_and_clear_bit (BNXT_PERIODIC_STATS_SP_EVENT , &bp->sp_event)) {bnxt_hwrm_port_qstats (bp,0 );bnxt_hwrm_port_qstats_ext (bp,0 ); +spin_lock (&bp->stats_lock);bnxt_accumulate_all_stats (bp); + bp->stats_updated_jiffies = jiffies; +spin_unlock (&bp->stats_lock); }if (test_and_clear_bit (BNXT_LINK_CHNG_SP_EVENT , &bp->sp_event)) {
@@ -14661,6 +14704,7 @@ static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)INIT_DELAYED_WORK (&bp->fw_reset_task, bnxt_fw_reset_task);spin_lock_init (&bp->ntp_fltr_lock); +spin_lock_init (&bp->stats_lock);#if BITS_PER_LONG ==32 spin_lock_init (&bp->db_lock);#endif
@@ -15217,6 +15261,7 @@ static void bnxt_get_queue_stats_rx(struct net_device *dev, int i,if (!bp->bnapi)return ; +bnxt_sync_ring_stats (bp); cpr = &bp->bnapi[i]->cp_ring; sw = cpr->stats.sw_stats;
@@ -15245,6 +15290,7 @@ static void bnxt_get_queue_stats_tx(struct net_device *dev, int i,if (!bp->tx_ring)return ; +bnxt_sync_ring_stats (bp); bnapi = bp->tx_ring[bp->tx_ring_map[i]].bnapi; sw = bnapi->cp_ring.stats.sw_stats;
drivers/net/ethernet/broadcom/bnxt/bnxt.h +5 -0
@@ -2518,6 +2518,10 @@ struct bnxt {#define BNXT_MIN_STATS_COAL_TICKS 250000#define BNXT_MAX_STATS_COAL_TICKS 1000000 +/* Protects stats_updated_jiffies and writes to sw_stats */ +spinlock_t stats_lock; +unsigned long stats_updated_jiffies; +struct work_struct sp_task;unsigned long sp_event;#define BNXT_RX_MASK_SP_EVENT 0
@@ -2866,6 +2870,7 @@ void bnxt_reenable_sriov(struct bnxt *bp);void bnxt_close_nic (struct bnxt *,bool ,bool );void bnxt_get_ring_drv_stats (struct bnxt *bp,struct bnxt_total_ring_drv_stats *stats); +void bnxt_sync_ring_stats (struct bnxt *bp);bool bnxt_rfs_capable (struct bnxt *bp,bool new_rss_ctx);int bnxt_dbg_hwrm_rd_reg (struct bnxt *bp,u32 reg_off,u16 num_words,u32 *reg_buf);
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +1 -0
@@ -604,6 +604,7 @@ static void bnxt_get_ethtool_stats(struct net_device *dev, goto skip_ring_stats; } +bnxt_sync_ring_stats (bp); tpa_stats =bnxt_get_num_tpa_ring_stats (bp);for (i =0 ; i < bp->cp_nr_rings; i++) {struct bnxt_napi *bnapi = bp->bnapi[i];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 639/1276 ipv4: fib: Dont ignore error route in local/main tables.
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit b72f0db64205d9ce462038ba995d5d31eff32dc1 ]
When CONFIG_IP_MULTIPLE_TABLES is enabled but no rule is added, fib_lookup() performs route lookup directly on two tables.
Since the first lookup does not properly bail out, the result of an error route in the merged local/main table could be overwritten by another route in the default table:
# unshare -n
# ip link set lo up
# ip route add 192.168.0.0/24 dev lo table 253
# ip route add unreachable 192.168.0.0/24
# ip route get 192.168.0.1
192.168.0.1 dev lo table default uid 0
cache <local>Once a random rule is added, the error route is respected:
# ip rule add table 0 # ip rule del table 0 # ip route get 192.168.0.1 RTNETLINK answers: No route to host
Let's fix the inconsistent behaviour.
--- include/net/ip_fib.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
include/net/ip_fib.h +3 -4
@@ -373,7 +373,7 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp, struct fib_result *res, unsigned int flags) {struct fib_table *tb; -int err = -ENETUNREACH ; +int err = -EAGAIN ; flags |=FIB_LOOKUP_NOREF ;if (net->ipv4.fib_has_custom_rules)
@@ -387,17 +387,16 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp,if (tb) err =fib_table_lookup (tb, flp, res, flags); -if (!err) +if (err != -EAGAIN ) goto out; tb =rcu_dereference_rtnl (net->ipv4.fib_default);if (tb) err =fib_table_lookup (tb, flp, res, flags); -out:if (err == -EAGAIN ) err = -ENETUNREACH ; - +out:rcu_read_unlock ();return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 640/1276 md/raid5: use stripe state snapshot in break_stripe_batch_list()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Cheng <[email protected]>
[ Upstream commit 9b249f5ffbeda24c57e6c56ed896c5ca4fc70549 ]
The patch just suppress KCSAN noise. No functional change.
RAID-5 can group multi full-stripe-write aka stripe_head into a batch aka batch_list, with one head_sh leading them. Call break_stripe_batch_list() when the batch is finished, or, a stripe has to be dropped out of the batch.
break_stripe_batch_list() reads stripe state several times while request paths can update thost state words concurrently with lockless bitops, which reported by KCSAN.
Use a snapshot to guarantees that the value used for warning, copying, and handle checks is internally consistent at current read moment.
KCSAN report:
==============================================
BUG: KCSAN: data-race in __add_stripe_bio / break_stripe_batch_list
write (marked) to 0xffff8e89d4f0b988 of 8 bytes by task 4323 on cpu 3:
__add_stripe_bio+0x35e/0x400 raid5_make_request+0x6ac/0x2930 md_handle_request+0x4a2/0xa40 md_submit_bio+0x109/0x1a0 __submit_bio+0x2ec/0x390 submit_bio_noacct_nocheck+0x457/0x710 submit_bio_noacct+0x2a7/0xc20 submit_bio+0x56/0x250 blkdev_direct_IO+0x54c/0xda0 blkdev_write_iter+0x38f/0x570 aio_write+0x22b/0x490 io_submit_one+0xa51/0xf70
read to 0xffff8e89d4f0b988 of 8 bytes by task 4290 on cpu 4:
break_stripe_batch_list+0x3ce/0x480 handle_stripe_clean_event+0x720/0x9b0 handle_stripe+0x32fb/0x4500 handle_active_stripes.isra.0+0x6e0/0xa50 raid5d+0x7e0/0xba0
Stable-dep-of: 55b77337bdd0 ("md/raid5: avoid R5_Overlap races while breaking stripe batches")
--- drivers/md/raid5.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-)
drivers/md/raid5.c +26 -19
@@ -4835,31 +4835,35 @@ static void break_stripe_batch_list(struct stripe_head *head_sh, {struct stripe_head *sh, *next;int i; +unsigned long state;list_for_each_entry_safe (sh, next, &head_sh->batch_list, batch_list) {list_del_init (&sh->batch_list); -WARN_ONCE (sh->state & ((1 <<STRIPE_ACTIVE ) | - (1 <<STRIPE_SYNCING ) | - (1 <<STRIPE_REPLACED ) | - (1 <<STRIPE_DELAYED ) | - (1 <<STRIPE_BIT_DELAY ) | - (1 <<STRIPE_FULL_WRITE ) | - (1 <<STRIPE_BIOFILL_RUN ) | - (1 <<STRIPE_COMPUTE_RUN ) | - (1 <<STRIPE_DISCARD ) | - (1 <<STRIPE_BATCH_READY ) | - (1 <<STRIPE_BATCH_ERR )), -"stripe state: %lx\n" , sh->state); -WARN_ONCE (head_sh->state & ((1 <<STRIPE_DISCARD ) | - (1 <<STRIPE_REPLACED )), -"head stripe state: %lx\n" , head_sh->state); + state =READ_ONCE (sh->state); +WARN_ONCE (state & ((1 <<STRIPE_ACTIVE ) | + (1 <<STRIPE_SYNCING ) | + (1 <<STRIPE_REPLACED ) | + (1 <<STRIPE_DELAYED ) | + (1 <<STRIPE_BIT_DELAY ) | + (1 <<STRIPE_FULL_WRITE ) | + (1 <<STRIPE_BIOFILL_RUN ) | + (1 <<STRIPE_COMPUTE_RUN ) | + (1 <<STRIPE_DISCARD ) | + (1 <<STRIPE_BATCH_READY ) | + (1 <<STRIPE_BATCH_ERR )), +"stripe state: %lx\n" , state); + + state =READ_ONCE (head_sh->state); +WARN_ONCE (state & ((1 <<STRIPE_DISCARD ) | + (1 <<STRIPE_REPLACED )), +"head stripe state: %lx\n" , state);set_mask_bits (&sh->state, ~(STRIPE_EXPAND_SYNC_FLAGS | (1 <<STRIPE_PREREAD_ACTIVE ) | (1 <<STRIPE_ON_UNPLUG_LIST )), - head_sh->state & (1 <<STRIPE_INSYNC )); + state & (1 <<STRIPE_INSYNC )); sh->check_state = head_sh->check_state; sh->reconstruct_state = head_sh->reconstruct_state;
@@ -4872,8 +4876,9 @@ static void break_stripe_batch_list(struct stripe_head *head_sh, sh->dev[i].flags = head_sh->dev[i].flags & (~((1 << R5_WriteError) | (1 << R5_Overlap))); } -if (handle_flags ==0 || - sh->state & handle_flags) + + state =READ_ONCE (sh->state); +if (handle_flags ==0 || (state & handle_flags))set_bit (STRIPE_HANDLE , &sh->state);raid5_release_stripe (sh); }
@@ -4883,7 +4888,9 @@ static void break_stripe_batch_list(struct stripe_head *head_sh,for (i =0 ; i < head_sh->disks; i++)if (test_and_clear_bit (R5_Overlap, &head_sh->dev[i].flags))wake_up_bit (&head_sh->dev[i].flags, R5_Overlap); -if (head_sh->state & handle_flags) + + state =READ_ONCE (head_sh->state); +if (state & handle_flags)set_bit (STRIPE_HANDLE , &head_sh->state); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 641/1276 md/raid5: avoid R5_Overlap races while breaking stripe batches
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Cheng <[email protected]>
[ Upstream commit 55b77337bdd088c77461588e5ec094421b89911b ]
KCSAN report a race in break_stripe_batch_list() vs. raid5_make_request() on sh->dev[i].flags (plain word write vs. atomic bit op)..
and .. one possible scenario is:
CPU1 CPU2break_stripe_batch_list(sh1)
-> handle sh2
-> lock(sh2)
-> sh2->batch_head = NULL
-> unlock(sh2)
-> test_and_clear_bit(R5_Overlap, sh2->dev[i].flags) -> wake_up_bit(sh2->dev[i].flags)
raid5_make_request()
-> add_all_stripe_bios(sh2)
-> lock(sh2)
-> stripe_bio_overlaps(sh2) returns true
batch_head is NULL, so new bio overlap
exist bio on sh2 -> true
-> set_bit(R5_Overlap, sh2->dev[i].flags)
-> unlock(sh2)
-> wait_on_bit(sh2->dev[i].flags)-> sh2->dev[i].flags = sh1->dev[i].flags & ~R5_Overlap
No wait_up_bit(), CPU2 could be wait_on_bit() forever...
Fix by :
- Expand the protect zone.
- Use batch_head's device flag's snaphot when no held head_sh->stripe_lock.
- Move sh/head_sh->batch_head = NULL to the end of protected zone , and , any concurrent add_all_stripe_bios() grabs sh->stripe_lock now either:
- see batch_head != null, and , is rejected by stripe_bio_overlaps() under the lock (no R5_Overlap wait ) , or ,
- sees batch_head == NULL, only after dev[i].flags has already been set and the prior R5_Overlap waiters worken.
KCSAN report:
================================================
BUG: KCSAN: data-race in break_stripe_batch_list / raid5_make_request
write (marked) to 0xffff8e89c8117548 of 8 bytes by task 4042 on cpu 0:
raid5_make_request+0xea0/0x2930
md_handle_request+0x4a2/0xa40
md_submit_bio+0x109/0x1a0
__submit_bio+0x2ec/0x390
submit_bio_noacct_nocheck+0x457/0x710
submit_bio_noacct+0x2a7/0xc20
submit_bio+0x56/0x250
blkdev_direct_IO+0x54c/0xda0
blkdev_write_iter+0x38f/0x570
aio_write+0x22b/0x490
io_submit_one+0xa51/0xf70
__x64_sys_io_submit+0xf7/0x220
x64_sys_call+0x1907/0x1c60
do_syscall_64+0x130/0x570
entry_SYSCALL_64_after_hwframe+0x76/0x7e read to 0xffff8e89c8117548 of 8 bytes by task 4010 on cpu 5:
break_stripe_batch_list+0x249/0x480
handle_stripe_clean_event+0x720/0x9b0
handle_stripe+0x32fb/0x4500
handle_active_stripes.isra.0+0x6e0/0xa50
raid5d+0x7e0/0xba0
md_thread+0x15a/0x2d0
kthread+0x1e3/0x220
ret_from_fork+0x37a/0x410
ret_from_fork_asm+0x1a/0x30 value changed: 0x0000000000000019 -> 0x0000000000000099 --> R5_Overlap
--- drivers/md/raid5.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/raid5.c +5 -5
@@ -4868,14 +4868,14 @@ static void break_stripe_batch_list(struct stripe_head *head_sh, sh->check_state = head_sh->check_state; sh->reconstruct_state = head_sh->reconstruct_state;spin_lock_irq (&sh->stripe_lock); - sh->batch_head =NULL ; -spin_unlock_irq (&sh->stripe_lock);for (i =0 ; i < sh->disks; i++) {if (test_and_clear_bit (R5_Overlap, &sh->dev[i].flags))wake_up_bit (&sh->dev[i].flags, R5_Overlap); - sh->dev[i].flags = head_sh->dev[i].flags & + sh->dev[i].flags =READ_ONCE (head_sh->dev[i].flags) & (~((1 << R5_WriteError) | (1 << R5_Overlap))); } + sh->batch_head =NULL ; +spin_unlock_irq (&sh->stripe_lock); state =READ_ONCE (sh->state);if (handle_flags ==0 || (state & handle_flags))
@@ -4883,11 +4883,11 @@ static void break_stripe_batch_list(struct stripe_head *head_sh,raid5_release_stripe (sh); }spin_lock_irq (&head_sh->stripe_lock); - head_sh->batch_head =NULL ; -spin_unlock_irq (&head_sh->stripe_lock);for (i =0 ; i < head_sh->disks; i++)if (test_and_clear_bit (R5_Overlap, &head_sh->dev[i].flags))wake_up_bit (&head_sh->dev[i].flags, R5_Overlap); + head_sh->batch_head =NULL ; +spin_unlock_irq (&head_sh->stripe_lock); state =READ_ONCE (head_sh->state);if (state & handle_flags)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 642/1276 bpf: Disable xfrm_decode_session hook attachment
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
[ Upstream commit 12091470c6b4c1c14b2de12dcbae2ada6cb6d20b ]
BPF LSM programs can currently attach to xfrm_decode_session(). That hook may return an error, but security_skb_classify_flow() calls it from a void path and triggers BUG_ON() if an error is returned.
Disable BPF attachment to the hook to prevent a BPF LSM program from turning packet classification into a full panic.
--- kernel/bpf/bpf_lsm.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/bpf/bpf_lsm.c +3 -0
@@ -50,6 +50,9 @@ BTF_ID(func, bpf_lsm_key_getsecurity)#ifdef CONFIG_AUDIT BTF_ID(func, bpf_lsm_audit_rule_match)#endif +#ifdef CONFIG_SECURITY_NETWORK_XFRM +BTF_ID(func, bpf_lsm_xfrm_decode_session) +#endif BTF_ID(func, bpf_lsm_ismaclabel)BTF_SET_END (bpf_lsm_disabled_hooks)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 643/1276 netfilter: nf_nat: avoid invalid nat_net pointer use on failed nf_nat_init()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mathias Krause <[email protected]>
[ Upstream commit 069cfe3de2a5e16069485893cd04665ab769c1d8 ]
We ran into below KASAN splat, which is mostly uninteresting, beside for having nf_nat_register_fn() in the call chain as a cause for the offending access:
==================================================================
BUG: KASAN: slab-out-of-bounds in nf_nat_register_fn+0x5f9/0x640 Read of size 8 at addr ffff890031e54c20 by task iptables/9510 CPU: 0 UID: 0 PID: 9510 Comm: iptables Not tainted 6.18.18-grsec-full-20260320181326 #1 PREEMPT(voluntary) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Call Trace: <TASK> […] dump_stack_lvl+0xee/0x160 ffff88004117eeb8 […] print_report+0x6e/0x640 ffff88004117eee0 […] ? __phys_addr+0x8e/0x140 ffff88004117eef0 […] ? kasan_addr_to_slab+0x51/0xe0 ffff88004117ef08 […] ? complete_report_info+0xec/0x1c0 ffff88004117ef20 […] ? nf_nat_register_fn+0x5f9/0x640 ffff88004117ef48 […] kasan_report+0xbc/0x140 ffff88004117ef50 […] ? nf_nat_register_fn+0x5f9/0x640 ffff88004117ef90 […] nf_nat_register_fn+0x5f9/0x640 ffff88004117eff8 […] ? nf_nat_icmp_reply_translation+0x6e0/0x6e0 ffff88004117f070 […] nf_tables_register_hook.part.0+0xa0/0x220 ffff88004117f080 […] nf_tables_addchain.constprop.0+0x1054/0x1fc0 ffff88004117f0b8 […] ? nft_chain_lookup.part.0+0x4ce/0xac0 ffff88004117f130 […] ? nf_tables_abort+0x3d80/0x3d80 ffff88004117f190 […] ? nf_tables_dumpreset_obj+0x100/0x100 ffff88004117f1c8 […] ? nft_table_lookup.part.0+0x255/0x300 ffff88004117f310 […] ? nf_tables_newchain+0x21a4/0x2fa0 ffff88004117f358 […] nf_tables_newchain+0x21a4/0x2fa0 ffff88004117f360 […] ? nf_tables_addchain.constprop.0+0x1fc0/0x1fc0 ffff88004117f458 […] ? nla_get_range_signed+0x4a0/0x4a0 ffff88004117f488 […] ? lock_acquire+0x16f/0x320 ffff88004117f490 […] ? find_held_lock+0x3b/0xe0 ffff88004117f4b0 […] ? __nla_parse+0x45/0x80 ffff88004117f500 […] nfnetlink_rcv_batch+0xbca/0x19a0 ffff88004117f550 […] ? nfnetlink_net_exit_batch+0x120/0x120 ffff88004117f618 […] ? __sanitizer_cov_trace_switch+0x63/0xe0 ffff88004117f720 […] ? gr_acl_handle_mmap+0x1c4/0x320 ffff88004117f7c0 […] ? nla_get_range_signed+0x4a0/0x4a0 ffff88004117f7e8 […] ? gr_is_capable+0x6f/0xe0 ffff88004117f830 […] ? __nla_parse+0x45/0x80 ffff88004117f860 […] ? skb_pull+0x103/0x1a0 ffff88004117f880 […] nfnetlink_rcv+0x3db/0x4a0 ffff88004117f8b0 […] ? nfnetlink_rcv_batch+0x19a0/0x19a0 ffff88004117f8d8 […] ? netlink_lookup+0xe2/0x240 ffff88004117f900 […] netlink_unicast+0x74b/0xb00 ffff88004117f930 […] ? netlink_attachskb+0xb20/0xb20 ffff88004117f980 […] ? __check_object_size+0x3e/0xaa0 ffff88004117f998 […] ? security_netlink_send+0x51/0x160 ffff88004117f9c8 […] netlink_sendmsg+0xa03/0x1200 ffff88004117f9f8 […] ? netlink_unicast+0xb00/0xb00 ffff88004117fa70 […] ? netlink_unicast+0xb00/0xb00 ffff88004117fac8 […] ? ____sys_sendmsg+0xe2a/0x1040 ffff88004117faf8 […] ____sys_sendmsg+0xe2a/0x1040 ffff88004117fb00 […] ? kernel_recvmsg+0x300/0x300 ffff88004117fb60 […] ? reacquire_held_locks+0xe9/0x260 ffff88004117fbc8 […] ___sys_sendmsg+0x138/0x200 ffff88004117fbf8 […] ? do_recvmmsg+0x7e0/0x7e0 ffff88004117fc30 […] ? lockdep_hardirqs_on_prepare+0x101/0x1e0 ffff88004117fc50 […] ? lock_acquire+0x16f/0x320 ffff88004117fd20 […] ? lock_acquire+0x16f/0x320 ffff88004117fd58 […] ? find_held_lock+0x3b/0xe0 ffff88004117fd70 […] __sys_sendmsg+0x17a/0x260 ffff88004117fdc8 […] ? __sys_sendmsg_sock+0x80/0x80 ffff88004117fdf0 […] ? syscall_trace_enter+0x15e/0x2c0 ffff88004117fe98 […] do_syscall_64+0x7d/0x400 ffff88004117fec8 […] entry_SYSCALL_64_safe_stack+0x4a/0x60 ffff88004117fef8 </TASK> ==================================================================
The out-of-bounds report, though, is a red herring as it is for an access that shouldn't have happened in the first place.
When nf_nat_init() fails to register its BPF kfuncs, it'll unwind and, among others, call unregister_pernet_subsys() to deregister its per-net ops. This makes the previously allocated net id available for reuse by the next caller of register_pernet_subsys(), in our case, synproxy. However, 'nat_net_id' will still hold the previously allocated value.
If nf_nat.o gets build as a module, all this doesn't matter. A failed initialization routine makes the module fail to load and any dependent module won't be able to load either. However, if nf_nat.o is built-in, a failing init won't /completely/ make its functionality unavailable to dependent modules, namely the code and static data is still there, free to be called by modules like nft_chain_nat.ko.
Case in point, nft_chain_nat registers hooks that'll call into nf_nat which, in our case, failed to initialize and therefore won't have a valid net id nor related net_nat object any more.
Code in nf_nat, namely nf_nat_register_fn() and nf_nat_unregister_fn(), still making use of the reallocated net id, lead to a type confusion as the call to net_generic() will no longer return memory belonging to an object suited to fit 'struct nat_net' but 'struct synproxy_net' instead. The latter is only 24 bytes on 64-bit systems, much smaller than struct nat_net which is 176 bytes, perfectly explaining the OOB KASAN report.
Detect and handle a failed nf_nat_init() by testing the 'nf_nat_hook' pointer which will be reset to NULL on initialization errors to prevent the usage of an invalid nat_net pointer.
As this check is only needed when nf_nat.o is built-in, guard it by '#ifndef MODULE...'.
--- net/netfilter/nf_nat_core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/netfilter/nf_nat_core.c +10 -0
@@ -1195,6 +1195,16 @@ int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops,struct nf_hook_ops *nat_ops;int i, ret; +#ifndef MODULE +/* If nf_nat_core is built-in and nf_nat_init() fails, dependent +* modules like nft_chain_nat.ko may still call this function. +* However, nat_net would be invalid, likely pointing to some other +* per-net structure. +*/ +if (WARN_ON_ONCE (!nf_nat_hook)) +return -EOPNOTSUPP ; +#endif +if (WARN_ON_ONCE (pf >=ARRAY_SIZE (nat_net->nat_proto_net)))return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 644/1276 netfilter: nf_conncount: prevent connlimit drops for early confirmed ct
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit c8b6f36f766991e3ebebec6596daee4b04dcbc49 ]
Commit 69894e5b4c5e ("netfilter: nft_connlimit: update the count if add was skipped") introduced a regression where packets for valid connections are dropped when using connlimit for soft-limiting scenarios.
The issue occurs when a new connection reuses a socket currently in the TIME_WAIT state. In this scenario, the connection tracking entry is evaluated as already confirmed. Previously, __nf_conncount_add() assumed that if a connection was confirmed and did not originate from the loopback interface, it should skip the addition and return -EEXIST.
Skipping the addition triggers a garbage collection run that cleans up the TIME_WAIT connection. Consequently, the active connection count drops to 0, which xt_connlimit mishandles, leading to the false rejection of the perfectly valid new connection.
Fix this by replacing the interface check with protocol-agnostic state checks. We now skip the tree insertion and preserve the lockless garbage collection optimization only if the connection is IPS_ASSURED. This allows early-confirmed setup packets (such as reused TIME_WAIT sockets or locally generated SYN-ACKs) to be properly evaluated and counted without falsely dropping. The goto check_connections path is maintained to ensure these setup packets are deduplicated correctly.
This has been tested with slowhttptest and HTTP server configured locally to ensure we are not breaking soft-limiting scenarios for local or external connections. In addition, it was tested with a OVS zone limit too.
--- net/netfilter/nf_conncount.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
net/netfilter/nf_conncount.c +5 -6
@@ -179,17 +179,16 @@ static int __nf_conncount_add(struct net *net,return -ENOENT ;if (ct &&nf_ct_is_confirmed (ct)) { -/* local connections are confirmed in postrouting so confirmation -* might have happened before hitting connlimit +/* Connection is confirmed but might still be in the setup phase. +* Only skip the tracking if it is fully assured. This guarantees +* that setup packets or retransmissions are properly counted and +* deduplicated. */ -if (skb->skb_iif !=LOOPBACK_IFINDEX ) { +if (test_bit (IPS_ASSURED_BIT , &ct->status)) { err = -EEXIST ; goto out_put; } -/* this is likely a local connection, skip optimization to avoid -* adding duplicates from a 'packet train' -*/ goto check_connections; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 645/1276 netfilter: nft_synproxy: stop bypassing the priv->info snapshot
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 11d4bc4e26fb66040a5b5d95e9abf37deac2b1fc ]
nft_synproxy_eval_v4() and nft_synproxy_eval_v6() already take a whole-object READ_ONCE() snapshot of the shared priv->info state before building the SYNACK reply, but nft_synproxy_tcp_options() still masks opts->options with priv->info.options from the live shared object.
When a named synproxy object is updated concurrently with SYN traffic, the eval path can then mix mss and timestamp handling from the local snapshot with an options mask taken from a newer configuration, so one SYNACK no longer reflects a coherent synproxy configuration.
Use info->options so nft_synproxy_tcp_options() stays on the same local snapshot that the eval path already copied from priv->info.
--- net/netfilter/nft_synproxy.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
net/netfilter/nft_synproxy.c +4 -5
@@ -23,14 +23,13 @@ static const struct nla_policy nft_synproxy_policy[NFTA_SYNPROXY_MAX + 1] = {static void nft_synproxy_tcp_options (struct synproxy_options *opts,const struct tcphdr *tcp,struct synproxy_net *snet, -struct nf_synproxy_info *info, -const struct nft_synproxy *priv) +struct nf_synproxy_info *info) {this_cpu_inc (snet->stats->syn_received);if (tcp->ece && tcp->cwr) opts->options |=NF_SYNPROXY_OPT_ECN ; - opts->options &= priv->info.options; + opts->options &= info->options; opts->mss_encode = opts->mss_option; opts->mss_option = info->mss;if (opts->options &NF_SYNPROXY_OPT_TIMESTAMP )
@@ -55,7 +54,7 @@ static void nft_synproxy_eval_v4(const struct nft_synproxy *priv,if (tcp->syn) {/* Initial SYN from client */ -nft_synproxy_tcp_options (opts, tcp, snet, &info, priv); +nft_synproxy_tcp_options (opts, tcp, snet, &info);synproxy_send_client_synack (net, skb, tcp, opts);consume_skb (skb); regs->verdict.code =NF_STOLEN ;
@@ -86,7 +85,7 @@ static void nft_synproxy_eval_v6(const struct nft_synproxy *priv,if (tcp->syn) {/* Initial SYN from client */ -nft_synproxy_tcp_options (opts, tcp, snet, &info, priv); +nft_synproxy_tcp_options (opts, tcp, snet, &info);synproxy_send_client_synack_ipv6 (net, skb, tcp, opts);consume_skb (skb); regs->verdict.code =NF_STOLEN ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 646/1276 netfilter: nft_compat: ebtables emulation must reject non-bridge targets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 9dbba7e694ec045f21ede2f892fb42b81b4e1692 ]
xtables targets return netfilter verdicts: NF_ACCEPT, NF_DROP, and so on. ebtables targets return incompatible verdicts: EBT_ACCEPT,EBT_DROP, ... We cannot allow fallback to NFPROTO_UNSPEC.
ebtables doesn't permit this since11ff7288beb2 ("netfilter: ebtables: reject non-bridge targets") but that commit missed the nft_compat layer.
--- net/netfilter/nft_compat.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
net/netfilter/nft_compat.c +21 -3
@@ -389,6 +389,22 @@ static int nft_target_validate(const struct nft_ctx *ctx,return 0 ; } +static int nft_target_bridge_validate (const struct nft_ctx *ctx, +const struct nft_expr *expr) +{ +struct xt_target *target = expr->ops->data; + +/* Do not allow UNSPEC to stand-in for NFPROTO_BRIDGE +* targets: they are incompatible. ebtables targets return +* EBT_ACCEPT, DROP and so on which are not compatible with +* NF_ACCEPT, NF_DROP and so on. +*/ +if (target->family !=NFPROTO_BRIDGE ) +return -ENOENT ; + +return nft_target_validate (ctx, expr); +} + static void __nft_match_eval(const struct nft_expr *expr, struct nft_regs *regs, const struct nft_pktinfo *pkt,
@@ -916,14 +932,16 @@ nft_target_select_ops(const struct nft_ctx *ctx, ops->init = nft_target_init; ops->destroy = nft_target_destroy; ops->dump = nft_target_dump; - ops->validate = nft_target_validate; ops->data = target; ops->reduce =NFT_REDUCE_READONLY ; -if (family ==NFPROTO_BRIDGE ) +if (family ==NFPROTO_BRIDGE ) { ops->eval = nft_target_eval_bridge; -else + ops->validate = nft_target_bridge_validate; + }else { ops->eval = nft_target_eval_xt; + ops->validate = nft_target_validate; + }return ops; err:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 647/1276 gpio: davinci: fix IRQ domain leak on devm_kzalloc failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qingshuang Fu <[email protected]>
[ Upstream commit 4e8eb6952aa6749726c6c3763ae0032a6332c24f ]
In davinci_gpio_irq_setup(), after successfully creating an IRQ domain with irq_domain_create_legacy(), a subsequent devm_kzalloc() failure in the bank loop causes the function to return -ENOMEM without removing the IRQ domain.
Unlike devm-managed resources, irq_domain_create_legacy() does not auto-clean up on probe failure, so the domain is leaked.
Fix by calling irq_domain_remove() before returning on allocation failure.
--- drivers/gpio/gpio-davinci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpio/gpio-davinci.c +3 -1
@@ -552,8 +552,10 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)sizeof (struct davinci_gpio_irq_data ), GFP_KERNEL); -if (!irqdata) +if (!irqdata) { +irq_domain_remove (chips->irq_domain);return -ENOMEM ; + } irqdata->regs = g; irqdata->bank_num = bank;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 648/1276 NTB: epf: Make db_valid_mask cover only real doorbell bits
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 6eb7e28f1f24a28234add38755687a7ed8bc2654 ]
ndev->db_count includes an unused doorbell slot due to the legacy extra offset in the peer doorbell path. db_valid_mask must cover only the real doorbell bits and exclude the unused slot.
Set db_valid_mask to BIT_ULL(db_count - 1) - 1.
--- drivers/ntb/hw/epf/ntb_hw_epf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/ntb/hw/epf/ntb_hw_epf.c +5 -1
@@ -560,7 +560,11 @@ static int ntb_epf_init_dev(struct ntb_epf_dev *ndev)return ret; } - ndev->db_valid_mask =BIT_ULL (ndev->db_count) -1 ; +/* +* ndev->db_count includes an extra skipped slot due to the legacy +* doorbell layout, hence -1. +*/ + ndev->db_valid_mask =BIT_ULL (ndev->db_count -1 ) -1 ; ndev->mw_count =readl (ndev->ctrl_reg +NTB_EPF_MW_COUNT ); ndev->spad_count =readl (ndev->ctrl_reg +NTB_EPF_SPAD_COUNT );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 649/1276 NTB: epf: Report 0-based doorbell vector via ntb_db_event()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 3147f0964cecca15e349cbfbdd6a28eb6d50379d ]
ntb_db_event() expects the vector number to be relative to the first doorbell vector starting at 0.
Vector 0 is reserved for link events in the EPF driver, so doorbells start at vector 1. However, both supported peers (ntb_hw_epf with pci-epf-ntb, and pci-epf-vntb) have historically skipped vector 1 and started doorbells at vector 2.
Pass (irq_no - 2) to ntb_db_event() so doorbells are reported as 0..N-1. If irq_no == 1 is ever observed, warn and ignore it, since the slot is reserved in the legacy layout and reporting it as DB#0 would collide with the real DB#0 slot.
--- drivers/ntb/hw/epf/ntb_hw_epf.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/ntb/hw/epf/ntb_hw_epf.c +13 -3
@@ -69,6 +69,12 @@ enum epf_ntb_bar { NTB_BAR_NUM, }; +enum epf_irq_slot { +EPF_IRQ_LINK =0 , +EPF_IRQ_RESERVED_DB ,/* Historically skipped slot */ +EPF_IRQ_DB_START , +}; +#define NTB_EPF_MAX_MW_COUNT (NTB_BAR_NUM - BAR_MW1)struct ntb_epf_dev {
@@ -322,10 +328,14 @@ static irqreturn_t ntb_epf_vec_isr(int irq, void *dev) irq_no = irq - ndev->irq_base; ndev->db_val = irq_no +1 ; -if (irq_no ==0 ) +if (irq_no ==EPF_IRQ_LINK ) {ntb_link_event (&ndev->ntb); -else -ntb_db_event (&ndev->ntb, irq_no); + }else if (irq_no ==EPF_IRQ_RESERVED_DB ) { +dev_warn_ratelimited (ndev->dev, +"Unexpected reserved doorbell slot IRQ received\n" ); + }else { +ntb_db_event (&ndev->ntb, irq_no -EPF_IRQ_DB_START ); + }return IRQ_HANDLED ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 650/1276 NTB: epf: Fix doorbell bitmask and IRQ vector handling
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 4fdea8dbb62d746429498e07385a3ba0b0f6d1ab ]
The EPF driver currently stores the incoming doorbell as a vector number (irq_no + 1) in db_val and db_clear() clears all bits unconditionally. This breaks db_read()/db_clear() semantics when multiple doorbells are used.
Store doorbells as a bitmask (BIT_ULL(vector)) and make db_clear(db_bits) clear only the specified bits. Use atomic64 operations as db_val is updated from interrupt context.
Once db_val is stored as a bitmask, the ISR's doorbell vector is used not only for ntb_db_event(), but also as the bit index for BIT_ULL(). The existing ISR derives that vector by subtracting pci_irq_vector(pdev,
0) from the Linux IRQ number passed to the handler, but Linux IRQ numbers are not guaranteed to be contiguous.
Pass per-vector context as request_irq() dev_id instead, so the ISR gets the device vector directly.
Validate the doorbell vector before updating db_val or calling ntb_db_event(), so an unexpected vector cannot create an invalid shift or be reported to NTB clients.
While at it, read and validate mw_count before requesting interrupt vectors. An unsupported memory-window count does not need IRQs, and failing before ntb_epf_init_isr() keeps the probe error path simple.
--- drivers/ntb/hw/epf/ntb_hw_epf.c | 61 +++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 22 deletions(-)
drivers/ntb/hw/epf/ntb_hw_epf.c +39 -22
@@ -6,6 +6,7 @@* Author: Kishon Vijay Abraham I <[email protected]> */ +#include <linux/atomic.h> #include <linux/delay.h> #include <linux/module.h> #include <linux/pci.h>
@@ -77,6 +78,13 @@ enum epf_irq_slot {#define NTB_EPF_MAX_MW_COUNT (NTB_BAR_NUM - BAR_MW1) +struct ntb_epf_dev ; + +struct ntb_epf_irq_ctx { +struct ntb_epf_dev *ndev; +unsigned int irq_no; +}; +struct ntb_epf_dev {struct ntb_dev ntb;struct device *dev;
@@ -96,9 +104,9 @@ struct ntb_epf_dev {unsigned int self_spad;unsigned int peer_spad; -int db_val; +atomic64_t db_val;u64 db_valid_mask; -int irq_base; +struct ntb_epf_irq_ctx irq_ctx[NTB_EPF_MAX_DB_COUNT +1 ]; };#define ntb_ndev (__ntb) container_of(__ntb, struct ntb_epf_dev, ntb)
@@ -322,11 +330,10 @@ static int ntb_epf_link_disable(struct ntb_dev *ntb)static irqreturn_t ntb_epf_vec_isr (int irq,void *dev) { -struct ntb_epf_dev *ndev = dev; -int irq_no; - - irq_no = irq - ndev->irq_base; - ndev->db_val = irq_no +1 ; +struct ntb_epf_irq_ctx *ctx = dev; +struct ntb_epf_dev *ndev = ctx->ndev; +unsigned int db_vector; +unsigned int irq_no = ctx->irq_no;if (irq_no ==EPF_IRQ_LINK ) {ntb_link_event (&ndev->ntb);
@@ -334,7 +341,17 @@ static irqreturn_t ntb_epf_vec_isr(int irq, void *dev)dev_warn_ratelimited (ndev->dev,"Unexpected reserved doorbell slot IRQ received\n" ); }else { -ntb_db_event (&ndev->ntb, irq_no -EPF_IRQ_DB_START ); + db_vector = irq_no -EPF_IRQ_DB_START ; +if (ndev->db_count <NTB_EPF_MIN_DB_COUNT || + db_vector >= ndev->db_count -1 ) { +dev_warn_ratelimited (ndev->dev, +"Unexpected doorbell vector %u (db_count %u)\n" , + db_vector, ndev->db_count); +return IRQ_HANDLED ; + } + +atomic64_or (BIT_ULL (db_vector), &ndev->db_val); +ntb_db_event (&ndev->ntb, db_vector); }return IRQ_HANDLED ;
@@ -361,18 +378,18 @@ static int ntb_epf_init_isr(struct ntb_epf_dev *ndev, int msi_min, int msi_max) argument &= ~MSIX_ENABLE ; } - ndev->irq_base =pci_irq_vector (pdev,0 ); + ndev->db_count = irq -1 ;for (i =0 ; i < irq; i++) { + ndev->irq_ctx[i].ndev = ndev; + ndev->irq_ctx[i].irq_no = i; ret =request_irq (pci_irq_vector (pdev, i), ntb_epf_vec_isr, -0 ,"ntb_epf" , ndev); +0 ,"ntb_epf" , &ndev->irq_ctx[i]);if (ret) {dev_err (dev,"Failed to request irq\n" ); goto err_free_irq; } } - ndev->db_count = irq -1 ; - ret =ntb_epf_send_command (ndev,CMD_CONFIGURE_DOORBELL , argument | irq);if (ret) {
@@ -384,7 +401,7 @@ static int ntb_epf_init_isr(struct ntb_epf_dev *ndev, int msi_min, int msi_max) err_free_irq:while (i--) -free_irq (pci_irq_vector (pdev, i), ndev); +free_irq (pci_irq_vector (pdev, i), &ndev->irq_ctx[i]);pci_free_irq_vectors (pdev);return ret;
@@ -509,7 +526,7 @@ static u64 ntb_epf_db_read(struct ntb_dev *ntb) {struct ntb_epf_dev *ndev =ntb_ndev (ntb); -return ndev->db_val; +return atomic64_read (&ndev->db_val); }static int ntb_epf_db_clear_mask (struct ntb_dev *ntb,u64 db_bits)
@@ -521,7 +538,7 @@ static int ntb_epf_db_clear(struct ntb_dev *ntb, u64 db_bits) {struct ntb_epf_dev *ndev =ntb_ndev (ntb); - ndev->db_val =0 ; +atomic64_and (~db_bits, &ndev->db_val);return 0 ; }
@@ -562,6 +579,12 @@ static int ntb_epf_init_dev(struct ntb_epf_dev *ndev)struct device *dev = ndev->dev;int ret; + ndev->mw_count =readl (ndev->ctrl_reg +NTB_EPF_MW_COUNT ); +if (ndev->mw_count >NTB_EPF_MAX_MW_COUNT ) { +dev_err (dev,"Unsupported MW count: %u\n" , ndev->mw_count); +return -EINVAL ; + } +/* One Link interrupt and rest doorbell interrupt */ ret =ntb_epf_init_isr (ndev,NTB_EPF_MIN_DB_COUNT +1 ,NTB_EPF_MAX_DB_COUNT +1 );
@@ -575,14 +598,8 @@ static int ntb_epf_init_dev(struct ntb_epf_dev *ndev)* doorbell layout, hence -1. */ ndev->db_valid_mask =BIT_ULL (ndev->db_count -1 ) -1 ; - ndev->mw_count =readl (ndev->ctrl_reg +NTB_EPF_MW_COUNT ); ndev->spad_count =readl (ndev->ctrl_reg +NTB_EPF_SPAD_COUNT ); -if (ndev->mw_count >NTB_EPF_MAX_MW_COUNT ) { -dev_err (dev,"Unsupported MW count: %u\n" , ndev->mw_count); -return -EINVAL ; - } -return 0 ; }
@@ -677,7 +694,7 @@ static void ntb_epf_cleanup_isr(struct ntb_epf_dev *ndev)ntb_epf_send_command (ndev,CMD_TEARDOWN_DOORBELL , ndev->db_count +1 );for (i =0 ; i < ndev->db_count +1 ; i++) -free_irq (pci_irq_vector (pdev, i), ndev); +free_irq (pci_irq_vector (pdev, i), &ndev->irq_ctx[i]);pci_free_irq_vectors (pdev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 651/1276 alpha/PCI: Add security_locked_down() check to pci_mmap_resource()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Wilczyński <[email protected]>
[ Upstream commit 78a228f0aa0e9eba31955950c8a40a9945e2c8bb ]
Currently, Alpha's pci_mmap_resource() does not check security_locked_down(LOCKDOWN_PCI_ACCESS) before allowing userspace to mmap PCI BARs.
The generic version has had this check since commit eb627e17727e ("PCI:
Lock down BAR access when the kernel is locked down") to prevent DMA attacks when the kernel is locked down.
Add the same check to Alpha's pci_mmap_resource().
--- arch/alpha/kernel/pci-sysfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/alpha/kernel/pci-sysfs.c +6 -1
@@ -11,6 +11,7 @@*/ #include <linux/sched.h> +#include <linux/security.h> #include <linux/stat.h> #include <linux/slab.h> #include <linux/pci.h>
@@ -71,7 +72,11 @@ static int pci_mmap_resource(struct kobject *kobj,struct resource *res = attr->private;enum pci_mmap_state mmap_type;struct pci_bus_region bar; -int i; +int i, ret; + + ret =security_locked_down (LOCKDOWN_PCI_ACCESS ); +if (ret) +return ret;for (i =0 ; i <PCI_STD_NUM_BARS ; i++)if (res == &pdev->resource[i])
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 652/1276 alpha/PCI: Fix __pci_mmap_fits() overflow for zero-length BARs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Wilczyński <[email protected]>
[ Upstream commit 802a3b3f470b9bc1148f26e01fc9cbfeb4dfcb57 ]
Currently, __pci_mmap_fits() computes the BAR size using "pci_resource_len() - 1", which wraps to a large value when the BAR length is zero, causing the bounds check to incorrectly succeed.
Add an early return for empty resources.
--- arch/alpha/kernel/pci-sysfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/alpha/kernel/pci-sysfs.c +5 -1
@@ -37,12 +37,16 @@ static int hose_mmap_page_range(struct pci_controller *hose,static int __pci_mmap_fits (struct pci_dev *pdev,int num,struct vm_area_struct *vma,int sparse) { +resource_size_t len =pci_resource_len (pdev, num);unsigned long nr, start, size;int shift = sparse ?5 :0 ; +if (!len) +return 0 ; + nr =vma_pages (vma); start = vma->vm_pgoff; - size = ((pci_resource_len (pdev, num) -1 ) >> (PAGE_SHIFT - shift)) +1 ; + size = ((len -1 ) >> (PAGE_SHIFT - shift)) +1 ;if (start < size && size - start >= nr)return 1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 653/1276 net, bpf: check master for NULL in xdp_master_redirect()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit e82d8cc4321c373dc46e741cd2dfdaa7921fddb7 ]
xdp_master_redirect() dereferences the result of netdev_master_upper_dev_get_rcu() without a NULL check, but that helper returns NULL when the receiving device has no upper-master adjacency.
The reach guard only checks netif_is_bond_slave(). On bond slave release bond_upper_dev_unlink() drops the upper-master adjacency before clearing IFF_SLAVE, so an XDP_TX reaching xdp_master_redirect() in that window still passes netif_is_bond_slave() while master is already NULL, and faults on master->flags at offset 0xb0:
BUG: kernel NULL pointer dereference, address: 00000000000000b0 RIP: 0010:xdp_master_redirect (net/core/filter.c:4432) Call Trace: xdp_master_redirect (net/core/filter.c:4432) bpf_prog_run_generic_xdp (include/net/xdp.h:700) do_xdp_generic (net/core/dev.c:5608) __netif_receive_skb_one_core (net/core/dev.c:6204) process_backlog (net/core/dev.c:6319) __napi_poll (net/core/dev.c:7729) net_rx_action (net/core/dev.c:7792) handle_softirqs (kernel/softirq.c:622) __dev_queue_xmit (include/linux/bottom_half.h:33) packet_sendmsg (net/packet/af_packet.c:3082) __sys_sendto (net/socket.c:2252) Kernel panic - not syncing: Fatal exception in interrupt
The missing check dates back to the original code; commit 1921f91298d1 ("net, bpf: fix null-ptr-deref in xdp_master_redirect() for down master") later added the master->flags read where the fault now lands but kept the unconditional deref. Check master for NULL before use; a NULL master is treated the same as one that is not up.
--- net/core/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/filter.c +1 -1
@@ -4427,7 +4427,7 @@ u32 xdp_master_redirect(struct xdp_buff *xdp)struct net_device *master, *slave; master =netdev_master_upper_dev_get_rcu (xdp->rxq->dev); -if (unlikely (!(master->flags &IFF_UP ))) +if (unlikely (!master || !(master->flags &IFF_UP )))return XDP_ABORTED ; slave = master->netdev_ops->ndo_xdp_get_xmit_slave (master, xdp);if (slave && slave != xdp->rxq->dev) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 654/1276 net: dsa: sja1105: round up PTP perout pin duration
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aleksandrova Alyona <[email protected]>
[ Upstream commit aee5836273b07b439fb245fb43930664d8b78518 ]
pin_duration is converted from the user-provided period to SJA1105 clock ticks and is later passed as the cycle_time argument to future_base_time().
Very small period values may become zero after the conversion, which can lead to a division by zero in future_base_time().
Round zero pin_duration up to 1 tick so that the smallest unsupported periods use the minimum non-zero hardware duration instead of passing zero to future_base_time().
--- drivers/net/dsa/sja1105/sja1105_ptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/sja1105/sja1105_ptp.c +1 -1
@@ -755,7 +755,7 @@ static int sja1105_per_out_enable(struct sja1105_private *priv,* 2 edges on PTP_CLK. So check for truncation which happens * at periods larger than around 68.7 seconds. */ - pin_duration =ns_to_sja1105_ticks (pin_duration /2 ); + pin_duration =max_t (u64,ns_to_sja1105_ticks (pin_duration /2 ),1 );if (pin_duration >U32_MAX ) { rc = -ERANGE ; goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 655/1276 veth: fix NAPI leak in XDP enable error path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 6739027cb72da26890edd424c77080d187b2a92e ]
During XDP enablement in veth, if xdp_rxq_info_reg() or xdp_rxq_info_reg_mem_model() fails, the driver rolls back the changes.
However, the rollback loop:
for (i--; i >= start; i--) {decrements the loop index 'i' before the first iteration. This correctly skips unregistering the rxq for the failed index 'i' (as registration failed or was already cleaned up), but it also erroneously skips calling netif_napi_deli() for rq[i].xdp_napi.
Since netif_napi_add() was already called for index 'i', this leaves a dangling napi_struct in the device's napi_list. When the veth device is later destroyed, the freed queue memory (which contains the leaked NAPI structure) can be reused.
The subsequent device teardown iterates the NAPI list and corrupts the reallocated memory, leading to UAF.
Fix this by explicitly deleting the NAPI association for the failed index 'i' before rolling back the successfully configured queues.
--- drivers/net/veth.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/veth.c +2 -0
@@ -1136,6 +1136,8 @@ static int veth_enable_xdp_range(struct net_device *dev, int start, int end, err_reg_mem:xdp_rxq_info_unreg (&priv->rq[i].xdp_rxq); err_rxq_reg: +if (!napi_already_on) +netif_napi_del (&priv->rq[i].xdp_napi);for (i--; i >= start; i--) {struct veth_rq *rq = &priv->rq[i];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 656/1276 net/sched: cls_api: Handle TC_ACT_CONSUMED in tcf_qevent_handle
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit a8a02897f2b479127db261de05cbf0c28b98d159 ]
tcf_classify() can return TC_ACT_CONSUMED while the skb is held by the defragmentation engine (e.g. act_ct on out-of-order fragments). When that happens the skb is no longer owned by the caller and must not be touched again.
tcf_qevent_handle() did not handle TC_ACT_CONSUMED: it fell through the switch and returned the skb to the caller as if classification had passed. The only qdisc that wires up qevents today is RED, via three call sites (qe_mark on RED_PROB_MARK/HARD_MARK, qe_early_drop on congestion_drop) red_enqueue() was continuing to operate on an skb it no longer owns in this case -- enqueueing it, dropping it, or updating statistics. Resulting in a UAF.
tc qdisc add dev eth0 root handle 1: red ... qevent early_drop block 10 tc filter add block 10 ... action ct
(with ct defrag enabled and traffic that produces out-of-order fragments, e.g. a fragmented UDP stream)
Handle TC_ACT_CONSUMED in tcf_qevent_handle() the same way the ingress and egress fast paths do: treat it as stolen and return NULL without touching the skb. Unlike the TC_ACT_STOLEN case, the skb must not be dropped/freed here, as it is no longer owned by us.
--- net/sched/cls_api.c | 3 +++ 1 file changed, 3 insertions(+)
net/sched/cls_api.c +3 -0
@@ -4039,6 +4039,9 @@ struct sk_buff *tcf_qevent_handle(struct tcf_qevent *qe, struct Qdisc *sch, struskb_do_redirect (skb); *ret = __NET_XMIT_STOLEN;return NULL ; +case TC_ACT_CONSUMED : + *ret = __NET_XMIT_STOLEN; +return NULL ; }return skb;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 657/1276 ipv6: fix error handling in disable_ipv6 sysctl
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit c779441e5070e2268bdfe77f6e2e0de926c431e3 ]
When writing to the disable_ipv6 sysctl, if proc_dointvec() fails to parse the input, it returns a negative error code. The current implementation is overwriting that error for write operations.
This results in a silent failure, it returns a successful write although the configuration was not modified at all. When modifying the "all" variant it can also modify the configuration of existing interfaces to the wrong value.
Fix this by checking the return value of proc_dointvec() and returning early on failure.
--- net/ipv6/addrconf.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/addrconf.c +2 -0
@@ -6458,6 +6458,8 @@ static int addrconf_sysctl_disable(const struct ctl_table *ctl, int write, lctl.data = &val; ret =proc_dointvec (&lctl, write, buffer, lenp, ppos); +if (ret) +return ret;if (write) ret =addrconf_disable_ipv6 (ctl, valp, val);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 658/1276 ipv6: fix error handling in ignore_routes_with_linkdown sysctl
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit cf4f2b14401f29ccac56393ca9e4b42a2505f540 ]
When writing to the ignore_routes_with_linkdown sysctl, if proc_dointvec() fails to parse the input, it returns a negative error code. The current implementation is overwriting that error for write operations.
This results in a silent failure, it returns a successful write although the configuration was not modified at all. When modifying the "all" variant it can also modify the configuration of existing interfaces to the wrong value.
Fix this by checking the return value of proc_dointvec() and returning early on failure.
--- net/ipv6/addrconf.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/addrconf.c +2 -0
@@ -6658,6 +6658,8 @@ int addrconf_sysctl_ignore_routes_with_linkdown(const struct ctl_table *ctl, lctl.data = &val; ret =proc_dointvec (&lctl, write, buffer, lenp, ppos); +if (ret) +return ret;if (write) ret =addrconf_fixup_linkdown (ctl, valp, val);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 659/1276 ipv6: fix error handling in forwarding sysctl
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 058b9b19f9639fe1e1225a17c540f61b65bee6ad ]
When writing to the forwarding sysctl, if proc_dointvec() fails to parse the input, it returns a negative error code. The current implementation is overwriting that error for write operations.
This results in a silent failure, it returns a successful write although the configuration was not modified at all. When modifying the "all" variant it can also modify the configuration of existing interfaces to the wrong value.
Fix this by checking the return value of proc_dointvec() and returning early on failure. In addition, adjust return code of addrconf_fixup_forwarding() for successful operation.
--- net/ipv6/addrconf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv6/addrconf.c +3 -1
@@ -907,7 +907,7 @@ static int addrconf_fixup_forwarding(const struct ctl_table *table, int *p, intif (newf)rt6_purge_dflt_routers (net); -return 1 ; +return 0 ; }static void addrconf_linkdown_change (struct net *net,__s32 newf)
@@ -6362,6 +6362,8 @@ static int addrconf_sysctl_forward(const struct ctl_table *ctl, int write, lctl.data = &val; ret =proc_dointvec (&lctl, write, buffer, lenp, ppos); +if (ret) +return ret;if (write) ret =addrconf_fixup_forwarding (ctl, valp, val);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 660/1276 ipv6: fix error handling in disable_policy sysctl
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 3e0e51c0ee1d08cc9d48dc17f3248d5b31cf8066 ]
When writing to the disable_policy sysctl, if proc_dointvec() fails to parse the input, it returns a negative error code. The current implementation is resetting the position argument even if an error occurred during proc_dointvec() and not only during sysctl restart.
Fix this by checking the return value of proc_dointvec() and returning early on failure.
--- net/ipv6/addrconf.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/addrconf.c +2 -0
@@ -6756,6 +6756,8 @@ static int addrconf_sysctl_disable_policy(const struct ctl_table *ctl, int write lctl = *ctl; lctl.data = &val; ret =proc_dointvec (&lctl, write, buffer, lenp, ppos); +if (ret) +return ret;if (write && (*valp != val)) ret =addrconf_disable_policy (ctl, valp, val);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 661/1276 rtnetlink: Add per-netns RTNL.
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 76aed95319da25d6884dff01d5f0149e4b542f96 ]
The goal is to break RTNL down into per-netns mutex.
This patch adds per-netns mutex and its helper functions, rtnl_net_lock() and rtnl_net_unlock().
rtnl_net_lock() acquires the global RTNL and per-netns RTNL mutex, and rtnl_net_unlock() releases them.
We will replace 800+ rtnl_lock() with rtnl_net_lock() and finally removes rtnl_lock() in rtnl_net_lock().
When we need to nest per-netns RTNL mutex, we will use __rtnl_net_lock(), and its locking order is defined by rtnl_net_lock_cmp_fn() as follows:
1. init_net is first
2. netns address ascending order
Note that the conversion will be done under CONFIG_DEBUG_NET_SMALL_RTNL with LOCKDEP so that we can carefully add the extra mutex without slowing down RTNL operations during conversion.
Stable-dep-of: 17dc3b245de4 ("ipv6: fix missing notification for ignore_routes_with_linkdown")
--- include/linux/rtnetlink.h | 21 ++++++++++++++ include/net/net_namespace.h | 4 +++ net/Kconfig.debug | 15 ++++++++++ net/core/net_namespace.c | 6 ++++ net/core/rtnetlink.c | 58 +++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+)
include/linux/rtnetlink.h +21 -0
@@ -95,6 +95,27 @@ static inline bool lockdep_rtnl_is_held(void)#define rcu_replace_pointer_rtnl (rp, p) \ rcu_replace_pointer(rp, p, lockdep_rtnl_is_held()) +#ifdef CONFIG_DEBUG_NET_SMALL_RTNL +void __rtnl_net_lock (struct net *net); +void __rtnl_net_unlock (struct net *net); +void rtnl_net_lock (struct net *net); +void rtnl_net_unlock (struct net *net); +int rtnl_net_lock_cmp_fn (const struct lockdep_map *a,const struct lockdep_map *b); +#else +static inline void __rtnl_net_lock (struct net *net) {} +static inline void __rtnl_net_unlock (struct net *net) {} + +static inline void rtnl_net_lock (struct net *net) +{ +rtnl_lock (); +} + +static inline void rtnl_net_unlock (struct net *net) +{ +rtnl_unlock (); +} +#endif +static inline struct netdev_queue *dev_ingress_queue (struct net_device *dev) {return rtnl_dereference (dev->ingress_queue);
include/net/net_namespace.h +4 -0
@@ -189,6 +189,10 @@ struct net {#if IS_ENABLED (CONFIG_SMC )struct netns_smc smc;#endif +#ifdef CONFIG_DEBUG_NET_SMALL_RTNL +/* Move to a better place when the config guard is removed. */ +struct mutex rtnl_mutex; +#endif } __randomize_layout;#include <linux/seq_file_net.h>
net/Kconfig.debug +15 -0
@@ -24,3 +24,18 @@ config DEBUG_NET help Enable extra sanity checks in networking. This is mostly used by fuzzers, but is safe to select. + +config DEBUG_NET_SMALL_RTNL + bool "Add extra per-netns mutex inside RTNL" + depends on DEBUG_KERNEL && NET && LOCK_DEBUGGING_SUPPORT + select PROVE_LOCKING + default n + help + rtnl_lock() is being replaced with rtnl_net_lock() that + acquires the global RTNL and a small per-netns RTNL mutex. + + During the conversion, rtnl_net_lock() just adds an extra + mutex in every RTNL scope and slows down the operations. + + Once the conversion completes, rtnl_lock() will be removed + and rtnetlink will gain per-netns scalability.
net/core/net_namespace.c +6 -0
@@ -334,6 +334,12 @@ static __net_init void preinit_net(struct net *net, struct user_namespace *user_idr_init (&net->netns_ids);spin_lock_init (&net->nsid_lock);mutex_init (&net->ipv4.ra_mutex); + +#ifdef CONFIG_DEBUG_NET_SMALL_RTNL +mutex_init (&net->rtnl_mutex); +lock_set_cmp_fn (&net->rtnl_mutex, rtnl_net_lock_cmp_fn,NULL ); +#endif +preinit_net_sysctl (net); }
net/core/rtnetlink.c +58 -0
64 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 662/1276 rtnetlink: Add assertion helpers for per-netns RTNL.
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 844e5e7e656d3a7a904fd5607f8491d6fd01db8e ]
Once an RTNL scope is converted with rtnl_net_lock(), we will replace RTNL helper functions inside the scope with the following per-netns alternatives:
ASSERT_RTNL() -> ASSERT_RTNL_NET(net)
rcu_dereference_rtnl(p) -> rcu_dereference_rtnl_net(net, p)
Note that the per-netns helpers are equivalent to the conventional helpers unless CONFIG_DEBUG_NET_SMALL_RTNL is enabled.
Stable-dep-of: 17dc3b245de4 ("ipv6: fix missing notification for ignore_routes_with_linkdown")
--- include/linux/rtnetlink.h | 45 +++++++++++++++++++++++++++++++++++---- net/core/rtnetlink.c | 12 +++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-)
include/linux/rtnetlink.h +41 -4
@@ -54,6 +54,10 @@ extern atomic_t dev_unreg_count;extern struct rw_semaphore pernet_ops_rwsem;extern struct rw_semaphore net_rwsem; +#define ASSERT_RTNL () \ + WARN_ONCE(!rtnl_is_locked(), \ + "RTNL: assertion failed at %s (%d)\n", __FILE__, __LINE__) +#ifdef CONFIG_PROVE_LOCKING extern bool lockdep_rtnl_is_held (void );#else
@@ -101,6 +105,22 @@ void __rtnl_net_unlock(struct net *net);void rtnl_net_lock (struct net *net);void rtnl_net_unlock (struct net *net);int rtnl_net_lock_cmp_fn (const struct lockdep_map *a,const struct lockdep_map *b); + +bool rtnl_net_is_locked (struct net *net); + +#define ASSERT_RTNL_NET (net) \ + WARN_ONCE(!rtnl_net_is_locked(net), \ + "RTNL_NET: assertion failed at %s (%d)\n", \ + __FILE__, __LINE__) + +bool lockdep_rtnl_net_is_held (struct net *net); + +#define rcu_dereference_rtnl_net (net, p) \ + rcu_dereference_check(p, lockdep_rtnl_net_is_held(net)) +#define rtnl_net_dereference (net, p) \ + rcu_dereference_protected(p, lockdep_rtnl_net_is_held(net)) +#define rcu_replace_pointer_rtnl_net (net, rp, p) \ + rcu_replace_pointer(rp, p, lockdep_rtnl_net_is_held(net))#else static inline void __rtnl_net_lock (struct net *net) {}static inline void __rtnl_net_unlock (struct net *net) {}
@@ -114,6 +134,27 @@ static inline void rtnl_net_unlock(struct net *net) {rtnl_unlock (); } + +static inline void ASSERT_RTNL_NET (struct net *net) +{ +ASSERT_RTNL (); +} + +static inline void *rcu_dereference_rtnl_net (struct net *net,void *p) +{ +return rcu_dereference_rtnl (p); +} + +static inline void *rtnl_net_dereference (struct net *net,void *p) +{ +return rtnl_dereference (p); +} + +static inline void *rcu_replace_pointer_rtnl_net (struct net *net, +void *rp,void *p) +{ +return rcu_replace_pointer_rtnl (rp, p); +}#endif static inline struct netdev_queue *dev_ingress_queue (struct net_device *dev)
@@ -143,10 +184,6 @@ void rtnetlink_init(void);void __rtnl_unlock (void );void rtnl_kfree_skbs (struct sk_buff *head,struct sk_buff *tail); -#define ASSERT_RTNL () \ - WARN_ONCE(!rtnl_is_locked(), \ - "RTNL: assertion failed at %s (%d)\n", __FILE__, __LINE__) - extern int ndo_dflt_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, struct net_device *dev,
net/core/rtnetlink.c +12 -0
@@ -235,6 +235,18 @@ int rtnl_net_lock_cmp_fn(const struct lockdep_map *a, const struct lockdep_map * return rtnl_net_cmp_locks(net_a, net_b); } + +bool rtnl_net_is_locked (struct net *net) +{ +return rtnl_is_locked () &&mutex_is_locked (&net->rtnl_mutex); +} +EXPORT_SYMBOL (rtnl_net_is_locked); + +bool lockdep_rtnl_net_is_held (struct net *net) +{ +return lockdep_rtnl_is_held () &&lockdep_is_held (&net->rtnl_mutex); +} +EXPORT_SYMBOL (lockdep_rtnl_net_is_held);#endif static struct rtnl_link __rcu *__rcu *rtnl_msg_handlers[RTNL_FAMILY_MAX +1 ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 663/1276 rtnetlink: Define rtnl_net_trylock().
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit d1c81818aa227b37d65b40f9883109c5256b9bfb ]
We will need the per-netns version of rtnl_trylock().
rtnl_net_trylock() calls __rtnl_net_lock() only when rtnl_trylock() successfully holds RTNL.
When RTNL is removed, we will use mutex_trylock() for per-netns RTNL.
Stable-dep-of: 17dc3b245de4 ("ipv6: fix missing notification for ignore_routes_with_linkdown")
--- include/linux/rtnetlink.h | 6 ++++++ net/core/rtnetlink.c | 11 +++++++++++ 2 files changed, 17 insertions(+)
include/linux/rtnetlink.h +6 -0
@@ -104,6 +104,7 @@ void __rtnl_net_lock(struct net *net);void __rtnl_net_unlock (struct net *net);void rtnl_net_lock (struct net *net);void rtnl_net_unlock (struct net *net); +int rtnl_net_trylock (struct net *net);int rtnl_net_lock_cmp_fn (const struct lockdep_map *a,const struct lockdep_map *b);bool rtnl_net_is_locked (struct net *net);
@@ -135,6 +136,11 @@ static inline void rtnl_net_unlock(struct net *net)rtnl_unlock (); } +static inline int rtnl_net_trylock (struct net *net) +{ +return rtnl_trylock (); +} +static inline void ASSERT_RTNL_NET (struct net *net) {ASSERT_RTNL ();
net/core/rtnetlink.c +11 -0
@@ -210,6 +210,17 @@ void rtnl_net_unlock(struct net *net) }EXPORT_SYMBOL (rtnl_net_unlock); +int rtnl_net_trylock (struct net *net) +{ +int ret =rtnl_trylock (); + +if (ret) +__rtnl_net_lock (net); + +return ret; +} +EXPORT_SYMBOL (rtnl_net_trylock); +static int rtnl_net_cmp_locks (const struct net *net_a,const struct net *net_b) {if (net_eq (net_a, net_b))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 664/1276 ipv6: Add __in6_dev_get_rtnl_net().
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit f7a6082b5e4c15f34fd766cf0960f7e082009c54 ]
We will convert rtnl_lock() with rtnl_net_lock(), and we want to convert __in6_dev_get() too.
__in6_dev_get() uses rcu_dereference_rtnl(), but as written in its comment, rtnl_dereference() or rcu_dereference() is preferable.
Let's add __in6_dev_get_rtnl_net() that uses rtnl_net_dereference().
We can add the RCU version helper later if needed.
Stable-dep-of: 17dc3b245de4 ("ipv6: fix missing notification for ignore_routes_with_linkdown")
--- include/net/addrconf.h | 5 +++++ 1 file changed, 5 insertions(+)
include/net/addrconf.h +5 -0
@@ -330,6 +330,11 @@ static inline struct inet6_dev *__in6_dev_get(const struct net_device *dev)return rcu_dereference_rtnl (dev->ip6_ptr); } +static inline struct inet6_dev *__in6_dev_get_rtnl_net (const struct net_device *dev) +{ +return rtnl_net_dereference (dev_net (dev), dev->ip6_ptr); +} +/** * __in6_dev_stats_get - get inet6_dev pointer for stats * @dev: network device
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 665/1276 ipv6: Convert net.ipv6.conf.${DEV}.XXX sysctl to per-netns RTNL.
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 93c839e3edbe2cdf59d3bc12d776cce4cdf159ce ]
net.ipv6.conf.${DEV}.XXX sysctl are changed under RTNL:
* forwarding
* ignore_routes_with_linkdown
* disable_ipv6
* proxy_ndp
* addr_gen_mode
* stable_secret
* disable_policy
Let's use rtnl_net_lock() there.
Stable-dep-of: 17dc3b245de4 ("ipv6: fix missing notification for ignore_routes_with_linkdown")
--- net/ipv6/addrconf.c | 60 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-)
net/ipv6/addrconf.c +30 -30
@@ -852,7 +852,7 @@ static void addrconf_forward_change(struct net *net, __s32 newf)struct inet6_dev *idev;for_each_netdev (net, dev) { - idev =__in6_dev_get (dev); + idev =__in6_dev_get_rtnl_net (dev);if (idev) {int changed = (!idev->cnf.forwarding) ^ (!newf);
@@ -865,13 +865,12 @@ static void addrconf_forward_change(struct net *net, __s32 newf)static int addrconf_fixup_forwarding (const struct ctl_table *table,int *p,int newf) { -struct net *net; +struct net *net = (struct net *)table->extra2;int old; -if (!rtnl_trylock ()) +if (!rtnl_net_trylock (net))return restart_syscall (); - net = (struct net *)table->extra2; old = *p;WRITE_ONCE (*p, newf);
@@ -881,7 +880,7 @@ static int addrconf_fixup_forwarding(const struct ctl_table *table, int *p, intNETCONFA_FORWARDING ,NETCONFA_IFINDEX_DEFAULT , net->ipv6.devconf_dflt); -rtnl_unlock (); +rtnl_net_unlock (net);return 0 ; }
@@ -903,7 +902,7 @@ static int addrconf_fixup_forwarding(const struct ctl_table *table, int *p, int net->ipv6.devconf_all); }else if ((!newf) ^ (!old))dev_forward_change ((struct inet6_dev *)table->extra1); -rtnl_unlock (); +rtnl_net_unlock (net);if (newf)rt6_purge_dflt_routers (net);
@@ -916,7 +915,7 @@ static void addrconf_linkdown_change(struct net *net, __s32 newf)struct inet6_dev *idev;for_each_netdev (net, dev) { - idev =__in6_dev_get (dev); + idev =__in6_dev_get_rtnl_net (dev);if (idev) {int changed = (!idev->cnf.ignore_routes_with_linkdown) ^ (!newf);
@@ -933,13 +932,12 @@ static void addrconf_linkdown_change(struct net *net, __s32 newf)static int addrconf_fixup_linkdown (const struct ctl_table *table,int *p,int newf) { -struct net *net; +struct net *net = (struct net *)table->extra2;int old; -if (!rtnl_trylock ()) +if (!rtnl_net_trylock (net))return restart_syscall (); - net = (struct net *)table->extra2; old = *p;WRITE_ONCE (*p, newf);
@@ -950,7 +948,7 @@ static int addrconf_fixup_linkdown(const struct ctl_table *table, int *p, int neNETCONFA_IGNORE_ROUTES_WITH_LINKDOWN ,NETCONFA_IFINDEX_DEFAULT , net->ipv6.devconf_dflt); -rtnl_unlock (); +rtnl_net_unlock (net);return 0 ; }
@@ -964,7 +962,8 @@ static int addrconf_fixup_linkdown(const struct ctl_table *table, int *p, int neNETCONFA_IFINDEX_ALL , net->ipv6.devconf_all); } -rtnl_unlock (); + +rtnl_net_unlock (net);return 1 ; }
@@ -6406,7 +6405,7 @@ static void addrconf_disable_change(struct net *net, __s32 newf)struct inet6_dev *idev;for_each_netdev (net, dev) { - idev =__in6_dev_get (dev); + idev =__in6_dev_get_rtnl_net (dev);if (idev) {int changed = (!idev->cnf.disable_ipv6) ^ (!newf);
@@ -6427,7 +6426,7 @@ static int addrconf_disable_ipv6(const struct ctl_table *table, int *p, int newfreturn 0 ; } -if (!rtnl_trylock ()) +if (!rtnl_net_trylock (net))return restart_syscall (); old = *p;
@@ -6436,10 +6435,11 @@ static int addrconf_disable_ipv6(const struct ctl_table *table, int *p, int newfif (p == &net->ipv6.devconf_all->disable_ipv6) {WRITE_ONCE (net->ipv6.devconf_dflt->disable_ipv6, newf);addrconf_disable_change (net, newf); - }else if ((!newf) ^ (!old)) + }else if ((!newf) ^ (!old)) {dev_disable_change ((struct inet6_dev *)table->extra1); + } -rtnl_unlock (); +rtnl_net_unlock (net);return 0 ; }
@@ -6484,20 +6484,20 @@ static int addrconf_sysctl_proxy_ndp(const struct ctl_table *ctl, int write,if (write && old != new) {struct net *net = ctl->extra2; -if (!rtnl_trylock ()) +if (!rtnl_net_trylock (net))return restart_syscall (); -if (valp == &net->ipv6.devconf_dflt->proxy_ndp) +if (valp == &net->ipv6.devconf_dflt->proxy_ndp) {inet6_netconf_notify_devconf (net,RTM_NEWNETCONF ,NETCONFA_PROXY_NEIGH ,NETCONFA_IFINDEX_DEFAULT , net->ipv6.devconf_dflt); -else if (valp == &net->ipv6.devconf_all->proxy_ndp) + }else if (valp == &net->ipv6.devconf_all->proxy_ndp) {inet6_netconf_notify_devconf (net,RTM_NEWNETCONF ,NETCONFA_PROXY_NEIGH ,NETCONFA_IFINDEX_ALL , net->ipv6.devconf_all); -else { + }else {struct inet6_dev *idev = ctl->extra1; inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
@@ -6505,7 +6505,7 @@ static int addrconf_sysctl_proxy_ndp(const struct ctl_table *ctl, int write, idev->dev->ifindex, &idev->cnf); } -rtnl_unlock (); +rtnl_net_unlock (net); }return ret;
@@ -6525,7 +6525,7 @@ static int addrconf_sysctl_addr_gen_mode(const struct ctl_table *ctl, int write, .mode = ctl->mode, }; -if (!rtnl_trylock ()) +if (!rtnl_net_trylock (net))return restart_syscall (); new_val = *((u32 *)ctl->data);
@@ -6555,7 +6555,7 @@ static int addrconf_sysctl_addr_gen_mode(const struct ctl_table *ctl, int write,WRITE_ONCE (net->ipv6.devconf_dflt->addr_gen_mode, new_val);for_each_netdev (net, dev) { - idev =__in6_dev_get (dev); + idev =__in6_dev_get_rtnl_net (dev);if (idev && idev->cnf.addr_gen_mode != new_val) { WRITE_ONCE(idev->cnf.addr_gen_mode,
@@ -6569,7 +6569,7 @@ static int addrconf_sysctl_addr_gen_mode(const struct ctl_table *ctl, int write, } out: -rtnl_unlock (); +rtnl_net_unlock (net);return ret; }
@@ -6591,7 +6591,7 @@ static int addrconf_sysctl_stable_secret(const struct ctl_table *ctl, int write, lctl.maxlen =IPV6_MAX_STRLEN ; lctl.data = str; -if (!rtnl_trylock ()) +if (!rtnl_net_trylock (net))return restart_syscall ();if (!write && !secret->initialized) {
@@ -6621,7 +6621,7 @@ static int addrconf_sysctl_stable_secret(const struct ctl_table *ctl, int write,struct net_device *dev;for_each_netdev (net, dev) { -struct inet6_dev *idev =__in6_dev_get (dev); +struct inet6_dev *idev =__in6_dev_get_rtnl_net (dev);if (idev) { WRITE_ONCE(idev->cnf.addr_gen_mode,
@@ -6636,7 +6636,7 @@ static int addrconf_sysctl_stable_secret(const struct ctl_table *ctl, int write, } out: -rtnl_unlock (); +rtnl_net_unlock (net);return err; }
@@ -6722,7 +6722,7 @@ int addrconf_disable_policy(const struct ctl_table *ctl, int *valp, int val)return 0 ; } -if (!rtnl_trylock ()) +if (!rtnl_net_trylock (net))return restart_syscall ();WRITE_ONCE (*valp, val);
@@ -6731,7 +6731,7 @@ int addrconf_disable_policy(const struct ctl_table *ctl, int *valp, int val)struct net_device *dev;for_each_netdev (net, dev) { - idev =__in6_dev_get (dev); + idev =__in6_dev_get_rtnl_net (dev);if (idev)addrconf_disable_policy_idev (idev, val); }
@@ -6740,7 +6740,7 @@ int addrconf_disable_policy(const struct ctl_table *ctl, int *valp, int val)addrconf_disable_policy_idev (idev, val); } -rtnl_unlock (); +rtnl_net_unlock (net);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 666/1276 ipv6: fix missing notification for ignore_routes_with_linkdown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 17dc3b245de45b1f2012e3a48ec51889f544e67b ]
When changing the ignore_routes_with_linkdown sysctl for a specific interface, the RTM_NEWNETCONF netlink notification was not being emitted to userspace. Fix this by emitting the notification when needed.
In addition, fix bogus return value for successful "all" and specific interface write operation leading to a wrong reset of the position pointer.
--- net/ipv6/addrconf.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
net/ipv6/addrconf.c +12 -6
@@ -948,11 +948,7 @@ static int addrconf_fixup_linkdown(const struct ctl_table *table, int *p, int neNETCONFA_IGNORE_ROUTES_WITH_LINKDOWN ,NETCONFA_IFINDEX_DEFAULT , net->ipv6.devconf_dflt); -rtnl_net_unlock (net); -return 0 ; - } - -if (p == &net->ipv6.devconf_all->ignore_routes_with_linkdown) { + }else if (p == &net->ipv6.devconf_all->ignore_routes_with_linkdown) {WRITE_ONCE (net->ipv6.devconf_dflt->ignore_routes_with_linkdown, newf);addrconf_linkdown_change (net, newf);if ((!newf) ^ (!old))
@@ -961,11 +957,21 @@ static int addrconf_fixup_linkdown(const struct ctl_table *table, int *p, int neNETCONFA_IGNORE_ROUTES_WITH_LINKDOWN ,NETCONFA_IFINDEX_ALL , net->ipv6.devconf_all); + }else { +if (!newf ^ !old) { +struct inet6_dev *idev = table->extra1; + +inet6_netconf_notify_devconf (net, +RTM_NEWNETCONF , +NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN , + idev->dev->ifindex, + &idev->cnf); + } }rtnl_net_unlock (net); -return 1 ; +return 0 ; }#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 667/1276 thermal: testing: zone: Flush work items during cleanup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit fb1a5dfe86d3af1e1c3ce168cf0d8d43897e0f77 ]
To prevent freed module code from being executed during the thermal testing module unload, make it add a dedicated workqueue for thermal testing work items and flush it in thermal_testing_exit().
--- drivers/thermal/testing/command.c | 36 ++++++++++++++++++++--- drivers/thermal/testing/thermal_testing.h | 8 +++++ drivers/thermal/testing/zone.c | 7 ++--- 3 files changed, 43 insertions(+), 8 deletions(-)
drivers/thermal/testing/command.c +32 -4
@@ -86,7 +86,10 @@#include "thermal_testing.h" -struct dentry *d_testing; +struct workqueue_struct *tt_wq__ro_after_init ; + +struct dentry *d_testing__ro_after_init ; +static struct dentry *d_command__ro_after_init ;#define TT_COMMAND_SIZE 16
@@ -213,17 +216,42 @@ static const struct file_operations tt_command_fops = {static int __init thermal_testing_init (void ) { +int error; + + tt_wq =alloc_workqueue ("thermal_testing" ,WQ_UNBOUND ,0 ); +if (!tt_wq) +return -ENOMEM ; + d_testing =debugfs_create_dir ("thermal-testing" ,NULL ); -if (!IS_ERR (d_testing)) -debugfs_create_file ("command" ,0200 , d_testing,NULL , - &tt_command_fops); +if (IS_ERR (d_testing)) { + error =PTR_ERR (d_testing); + goto destroy_wq; + } + + d_command =debugfs_create_file ("command" ,0200 , d_testing,NULL , &tt_command_fops); +if (IS_ERR (d_command)) { + error =PTR_ERR (d_command); + goto remove_d_testing; + }return 0 ; + +remove_d_testing: +debugfs_remove (d_testing); +destroy_wq: +destroy_workqueue (tt_wq); +return error; }module_init (thermal_testing_init); static void __exit thermal_testing_exit(void) { +/* First, prevent new commands from being entered. */ +debugfs_remove (d_command); +/* Flush commands in progress (if any). */ +flush_workqueue (tt_wq); +destroy_workqueue (tt_wq); +/* Remove the directory structure and clean up. */ debugfs_remove (d_testing);tt_zone_cleanup (); }
drivers/thermal/testing/thermal_testing.h +8 -0
@@ -1,4 +1,12 @@/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/workqueue.h> + +extern struct workqueue_struct *tt_wq; + +static inline void tt_queue_work (struct work_struct *work) +{ +queue_work (tt_wq, work); +}extern struct dentry *d_testing;
drivers/thermal/testing/zone.c +3 -4
@@ -13,7 +13,6 @@#include <linux/idr.h> #include <linux/list.h> #include <linux/thermal.h> -#include <linux/workqueue.h> #include "thermal_testing.h"
@@ -209,7 +208,7 @@ int tt_add_tz(void)INIT_WORK (&tt_work->work, tt_add_tz_work_fn); tt_work->tt_zone =no_free_ptr (tt_zone); -schedule_work (&(no_free_ptr (tt_work)->work)); +tt_queue_work (&(no_free_ptr (tt_work)->work));return 0 ; }
@@ -272,7 +271,7 @@ int tt_del_tz(const char *arg)INIT_WORK (&tt_work->work, tt_del_tz_work_fn); tt_work->tt_zone = tt_zone; -schedule_work (&(no_free_ptr (tt_work)->work)); +tt_queue_work (&(no_free_ptr (tt_work)->work));return 0 ; }
@@ -369,7 +368,7 @@ int tt_zone_add_trip(const char *arg)INIT_WORK (&tt_work->work, tt_zone_add_trip_work_fn); tt_work->tt_zone =no_free_ptr (tt_zone); tt_work->tt_trip =no_free_ptr (tt_trip); -schedule_work (&(no_free_ptr (tt_work)->work)); +tt_queue_work (&(no_free_ptr (tt_work)->work));return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 668/1276 ACPI: processor_idle: Mark LPI enter functions as __cpuidle
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit 956ca5d72c76504824c8eb601879da9476973e15 ]
When function tracing or Kprobes is enabled, entering an ACPI Low Power Idle (LPI) state triggers the following RCU splat:
RCU not on for: acpi_idle_lpi_enter+0x4/0xd8
WARNING: CPU: 8 PID: 0 at include/linux/trace_recursion.h:162 function_trace_call+0x1e8/0x228
The acpi_idle_lpi_enter() function is invoked within the cpuidle path after RCU has already been disabled for the current local CPU. Consequently, ftrace's function_trace_call() expects RCU to be actively watching before recording trace data, emitting a warning if it is not.
Fix this by annotating acpi_idle_lpi_enter(), the generic __weak stub, and the RISC-V implementation of acpi_processor_ffh_lpi_enter() with __cpuidle. This moves these functions into the '.cpuidle.text' section, implicitly disabling ftrace instrumentation (notrace) along this sensitive path and preventing trace-induced RCU warnings during idle entry.
--- drivers/acpi/processor_idle.c | 4 ++-- drivers/acpi/riscv/cpuidle.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/acpi/processor_idle.c +2 -2
@@ -1167,7 +1167,7 @@ static int acpi_processor_get_lpi_info(struct acpi_processor *pr)return 0 ; } -int __weak acpi_processor_ffh_lpi_enter (struct acpi_lpi_state *lpi) +int __weak __cpuidle acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi) {return -ENODEV ; }
@@ -1180,7 +1180,7 @@ int __weak acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi)* * Return: 0 for success or negative value for error */ -static int acpi_idle_lpi_enter (struct cpuidle_device *dev, +static int __cpuidle acpi_idle_lpi_enter(struct cpuidle_device *dev,struct cpuidle_driver *drv,int index) {struct acpi_processor *pr;
drivers/acpi/riscv/cpuidle.c +1 -1
@@ -66,7 +66,7 @@ int acpi_processor_ffh_lpi_probe(unsigned int cpu)return acpi_cpu_init_idle (cpu); } -int acpi_processor_ffh_lpi_enter (struct acpi_lpi_state *lpi) +int __cpuidle acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi) {u32 state = lpi->address;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 669/1276 smb/client: preserve errors from smb2_set_sparse()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Huiwen He <[email protected]>
[ Upstream commit 2a4b3d2db5c6fcdba889baf7b2ae5661b0beac89 ]
smb2_set_sparse() converts every FSCTL_SET_SPARSE failure to false and marks sparse support as broken for the share. Callers therefore report EOPNOTSUPP even for errors such as ENOSPC or EACCES, and later sparse operations remain disabled until the share is unmounted.
Return the SMB2 ioctl error directly. Set broken_sparse_sup only for EOPNOTSUPP, which indicates that the server does not support the request.
Update smb3_punch_hole() to propagate the error returned by smb2_set_sparse().
--- fs/smb/client/smb2ops.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
fs/smb/client/smb2ops.c +15 -15
@@ -2017,8 +2017,9 @@ smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid, }/* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */ -static bool smb2_set_sparse (const unsigned int xid,struct cifs_tcon *tcon, -struct cifsFileInfo *cfile,struct inode *inode,__u8 setsparse) +static int smb2_set_sparse (const unsigned int xid,struct cifs_tcon *tcon, +struct cifsFileInfo *cfile,struct inode *inode, +__u8 setsparse) {struct cifsInodeInfo *cifsi;int rc;
@@ -2027,31 +2028,31 @@ static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,/* if file already sparse don't bother setting sparse again */ if ((cifsi->cifsAttrs &FILE_ATTRIBUTE_SPARSE_FILE ) && setsparse) -return true;/* already sparse */ +return 0 ;/* already sparse */ if (!(cifsi->cifsAttrs &FILE_ATTRIBUTE_SPARSE_FILE ) && !setsparse) -return true;/* already not sparse */ +return 0 ;/* already not sparse */ /* * Can't check for sparse support on share the usual way via the * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share * since Samba server doesn't set the flag on the share, yet * supports the set sparse FSCTL and returns sparse correctly -* in the file attributes. If we fail setting sparse though we -* mark that server does not support sparse files for this share -* to avoid repeatedly sending the unsupported fsctl to server -* if the file is repeatedly extended. +* in the file attributes. If the server returns EOPNOTSUPP, mark +* that sparse files are not supported on this share to avoid +* repeatedly sending the unsupported FSCTL. */ if (tcon->broken_sparse_sup) -return false; +return -EOPNOTSUPP ; rc =SMB2_ioctl (xid, tcon, cfile->fid.persistent_fid, cfile->fid.volatile_fid,FSCTL_SET_SPARSE , &setsparse,1 , CIFSMaxBufSize,NULL ,NULL );if (rc) { - tcon->broken_sparse_sup = true; +if (rc == -EOPNOTSUPP ) + tcon->broken_sparse_sup = true;cifs_dbg (FYI ,"set sparse rc = %d\n" , rc); -return false; +return rc; }if (setsparse)
@@ -2059,7 +2060,7 @@ static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,else cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE ); -return true; +return 0 ; } static int
@@ -3387,10 +3388,9 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,inode_lock (inode);/* Need to make file sparse, if not already, before freeing range. */ /* Consider adding equivalent for compressed since it could also work */ -if (!smb2_set_sparse (xid, tcon, cfile, inode, set_sparse)) { - rc = -EOPNOTSUPP ; + rc =smb2_set_sparse (xid, tcon, cfile, inode, set_sparse); +if (rc) goto out; - }filemap_invalidate_lock (inode->i_mapping);/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 670/1276 rtc: ds1307: Fix off-by-one issue with wday for rx8130
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fredrik M Olsson <[email protected]>
[ Upstream commit 6882aab3c66112b33b251be95c09c8ead3e8d580 ]
The RTC represent each weekday with a individual bit set in the WDAY register, where the 0th bit represent the first day of the week and the 6th bit represents the last day of the week. For each passed day the chip performs a rotary-left-shift by one to advance the weekday by one.
The tm_wday field represent weekdays by a value in the range of 0-6.
The fls() function return the bit index of the last bit set. To handle when there are no bits set it will return 0, and if the 0th bit is set it will return 1, and if the 1st bit is set it will return 2, and so on.
In order to make the result of the fls() function fall into the expected range of 0-6 (instead of 1-7) this patch subtracts one from the result (which matches how the value is written in ds1307_set_time()).
--- drivers/rtc/rtc-ds1307.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-ds1307.c +1 -1
@@ -311,7 +311,7 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t) t->tm_hour =bcd2bin (tmp);/* rx8130 is bit position, not BCD */ if (ds1307->type == rx_8130) - t->tm_wday =fls (regs[DS1307_REG_WDAY ] &0x7f ); + t->tm_wday =fls (regs[DS1307_REG_WDAY ] &0x7f ) -1 ;else t->tm_wday =bcd2bin (regs[DS1307_REG_WDAY ] &0x07 ) -1 ; t->tm_mday =bcd2bin (regs[DS1307_REG_MDAY ] &0x3f );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 671/1276 rtc: cmos: unregister HPET IRQ handler on probe failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
[ Upstream commit a5bb580df018b5d1c5668f05f7979044fb19e23a ]
cmos_do_probe() registers cmos_interrupt() as the HPET RTC IRQ handler before requesting the RTC IRQ and registering the RTC device. If either request_irq() or devm_rtc_register_device() fails afterwards, the error path leaves the HPET RTC IRQ handler installed. This leaves a stale handler behind and make a later hpet_register_irq_handler() fail with -EBUSY.
Track whether the HPET handler was registered successfully and undo the registration on the probe error path. Also mask the HPET RTC IRQ bits to match the normal shutdown cleanup.
--- drivers/rtc/rtc-cmos.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/rtc/rtc-cmos.c +6 -0
@@ -932,6 +932,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)unsigned char rtc_control;unsigned address_space;u32 flags =0 ; +bool hpet_registered = false;struct nvmem_config nvmem_cfg = { .name ="cmos_nvram" , .word_size =1 ,
@@ -1089,6 +1090,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) " failed in rtc_init()."); goto cleanup1; } + hpet_registered = true; }else rtc_cmos_int_handler = cmos_interrupt;
@@ -1138,6 +1140,10 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)if (is_valid_irq (rtc_irq))free_irq (rtc_irq, cmos_rtc.rtc); cleanup1: +if (hpet_registered) { +hpet_mask_rtc_irq_bit (RTC_IRQMASK ); +hpet_unregister_irq_handler (cmos_interrupt); + } cmos_rtc.dev =NULL ; cleanup0:if (RTC_IOMAPPED )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 672/1276 net: dsa: realtek: fix memory leak in rtl8366rb_setup_led()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Yang <[email protected]>
[ Upstream commit 056a5087d87ead77dedbe9cf5bde53b7cd4b4651 ]
led_classdev_register_ext() only reads init_data.devicename - it never stores the pointer. However, the caller allocated devicename with kasprintf() but never freed it, leaking the string memory.
Fix it with a stack buffer to avoid dynamic buffers completely.
--- drivers/net/dsa/realtek/rtl8366rb-leds.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/dsa/realtek/rtl8366rb-leds.c +4 -4
@@ -89,6 +89,7 @@ static int rtl8366rb_setup_led(struct realtek_priv *priv, struct dsa_port *dp,struct led_init_data init_data = { };enum led_default_state state;struct rtl8366rb_led *led; +char name[64 ];u32 led_group;int ret;
@@ -129,10 +130,9 @@ static int rtl8366rb_setup_led(struct realtek_priv *priv, struct dsa_port *dp, init_data.fwnode = led_fwnode; init_data.devname_mandatory = true; - init_data.devicename =kasprintf (GFP_KERNEL ,"Realtek-%d:0%d:%d" , - dp->ds->index, dp->index, led_group); -if (!init_data.devicename) -return -ENOMEM ; +snprintf (name,sizeof (name),"Realtek-%d:0%d:%d" , + dp->ds->index, dp->index, led_group); + init_data.devicename = name; ret =devm_led_classdev_register_ext (priv->dev, &led->cdev, &init_data);if (ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 673/1276 octeontx2-af: Validate NIX maximum LFs correctly
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Subbaraya Sundeep <[email protected]>
[ Upstream commit 1576d12a39860418d6a68b402fda71a48f04a57c ]
NIX maximum number of LFs can be set via devlink command but that can be done before assigning any LFs to a PF/VF. The condition used to check whether any LFs are assigned is incorrect. This patch fixes that condition.
--- .../marvell/octeontx2/af/rvu_devlink.c | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c +19 -8
@@ -1399,7 +1399,9 @@ static int rvu_af_dl_nix_maxlf_validate(struct devlink *devlink, u32 id,struct rvu_devlink *rvu_dl =devlink_priv (devlink);struct rvu *rvu = rvu_dl->rvu;u16 max_nix0_lf, max_nix1_lf; -struct npc_mcam *mcam; +struct rvu_block *block; +int blkaddr =0 ; +int free_lfs;u64 cfg; cfg =rvu_read64 (rvu,BLKADDR_NIX0 ,NIX_AF_CONST2 );
@@ -1407,14 +1409,23 @@ static int rvu_af_dl_nix_maxlf_validate(struct devlink *devlink, u32 id, cfg =rvu_read64 (rvu,BLKADDR_NIX1 ,NIX_AF_CONST2 ); max_nix1_lf = cfg &0xFFF ; -/* Do not allow user to modify maximum NIX LFs while mcam entries -* have already been assigned. +/* Do not allow user to modify maximum NIX LFs while NIX LFs +* have already been assigned. Note that modifying NIX LFs count +* can be done only before any LF attach requests from PFs and VFs +* and not later or concurrently. */ - mcam = &rvu->hw->mcam; -if (mcam->bmap_fcnt < mcam->bmap_entries) { -NL_SET_ERR_MSG_MOD (extack, -"mcam entries have already been assigned, can't resize" ); -return -EPERM ; + blkaddr =rvu_get_next_nix_blkaddr (rvu, blkaddr); +while (blkaddr) { + block = &rvu->hw->block[blkaddr]; + + free_lfs =rvu_rsrc_free_count (&block->lf); +if (free_lfs != block->lf.max) { +NL_SET_ERR_MSG_MOD (extack, +"NIX LFs already assigned, can't resize" ); +return -EPERM ; + } + + blkaddr =rvu_get_next_nix_blkaddr (rvu, blkaddr); }if (max_nix0_lf && val.vu16 > max_nix0_lf) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 674/1276 net: mvneta: re-enable percpu interrupt on resume
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yun Zhou <[email protected]>
[ Upstream commit fd398d6480987e4c84fff0aaab6b9d6642a93343 ]
On Marvell MPIC platforms (Armada 370/XP/38x), mvneta uses a percpu IRQ disable/enable scheme for NAPI: the ISR (mvneta_percpu_isr) calls disable_percpu_irq() to mask the MPIC per-CPU interrupt and schedules NAPI poll, which calls enable_percpu_irq() on completion to unmask.
If suspend occurs while NAPI poll is pending (between disable_percpu_irq in the ISR and enable_percpu_irq in poll completion), the interrupt is never re-enabled:
1. mvneta_percpu_isr: disable_percpu_irq() + napi_schedule() => MPIC masked, percpu_enabled cpumask bit cleared
2. NAPI poll does not complete before suspend proceeds (on PREEMPT_RT this is highly likely since softirqs run in ksoftirqd which gets frozen; on non-RT it can happen when softirq processing is deferred to ksoftirqd)
3. mvneta_stop_dev => napi_disable(): cancels the pending poll without executing the completion path
4. suspend_device_irqs => IRQCHIP_MASK_ON_SUSPEND: masks MPIC (already masked, but records IRQS_SUSPENDED)
5. Resume: mpic_resume checks irq_percpu_is_enabled() => false (bit was cleared in step 1) => skips unmask
6. mvneta_start_dev only restores device-level INTR_NEW_MASK, does not touch the MPIC per-CPU mask
Result: MPIC per-CPU interrupt stays masked permanently. The NIC generates interrupts (INTR_NEW_CAUSE != 0) but the CPU never receives them, causing complete loss of network connectivity.
Fix by calling on_each_cpu(mvneta_percpu_enable) in the resume path to unconditionally unmask the MPIC per-CPU interrupt regardless of pre-suspend state.
--- drivers/net/ethernet/marvell/mvneta.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/marvell/mvneta.c +3 -0
@@ -5866,6 +5866,9 @@ static int mvneta_resume(struct device *device)rtnl_unlock ();mvneta_set_rx_mode (dev); +if (!pp->neta_armada3700) +on_each_cpu (mvneta_percpu_enable, pp, true); + return 0; }#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 675/1276 net: sungem: fix probe error cleanup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 36dea2f639249460d13f6ca66b2a9064187cd34d ]
gem_init_one() calls gem_remove_one() when register_netdev() fails. gem_remove_one() unregisters and frees resources owned by the net_device, including the DMA block, MMIO mapping, PCI regions, and the net_device itself. gem_init_one() then falls through to its own cleanup labels and frees the same resources again.
Keep the register_netdev() error path in gem_init_one(): clear drvdata so PM/remove paths do not see a half-registered device, remove the NAPI instance added during probe, and let the existing cleanup labels release the resources once.
The issue was found by a local static-analysis checker for probe error paths. The reported path was manually inspected before sending this fix.
Compile-tested with CONFIG_SUNGEM=y. Runtime testing was not performed because no sungem hardware is available.
--- drivers/net/ethernet/sun/sungem.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/net/ethernet/sun/sungem.c +9 -4
@@ -2986,10 +2986,10 @@ static int gem_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dev->max_mtu =GEM_MAX_MTU ;/* Register with kernel */ -if (register_netdev (dev)) { + err =register_netdev (dev); +if (err) {pr_err ("Cannot register net device, aborting\n" ); - err = -ENOMEM ; - goto err_out_free_consistent; + goto err_out_clear_drvdata; }/* Undo the get_cell with appropriate locking (we could use
@@ -3003,8 +3003,13 @@ static int gem_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dev->dev_addr);return 0 ; +err_out_clear_drvdata: +pci_set_drvdata (pdev,NULL ); +netif_napi_del (&gp->napi); + err_out_free_consistent: -gem_remove_one (pdev); +dma_free_coherent (&pdev->dev,sizeof (struct gem_init_block ), + gp->init_block, gp->gblock_dvma); err_out_iounmap:gem_put_cell (gp);iounmap (gp->regs);
Signature · 1 line
2.53.0