From: Sasha Levin Date: Wed, 25 Oct 2023 11:48:02 +0000 (-0400) Subject: Fixes for 5.10 X-Git-Tag: v6.1.61~81 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6ab24c55f6f5443842e981d8aaf3d07775cbb98a;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 5.10 Signed-off-by: Sasha Levin --- diff --git a/queue-5.10/mcb-lpc-reallocate-memory-region-to-avoid-memory-ove.patch b/queue-5.10/mcb-lpc-reallocate-memory-region-to-avoid-memory-ove.patch new file mode 100644 index 00000000000..910493be0e8 --- /dev/null +++ b/queue-5.10/mcb-lpc-reallocate-memory-region-to-avoid-memory-ove.patch @@ -0,0 +1,93 @@ +From d876d1c353cd9a2b0f7ccc2d0c88fcd2b0ed49b5 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 11 Apr 2023 10:33:29 +0200 +Subject: mcb-lpc: Reallocate memory region to avoid memory overlapping +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Rodríguez Barbarin, José Javier + +[ Upstream commit 2025b2ca8004c04861903d076c67a73a0ec6dfca ] + +mcb-lpc requests a fixed-size memory region to parse the chameleon +table, however, if the chameleon table is smaller that the allocated +region, it could overlap with the IP Cores' memory regions. + +After parsing the chameleon table, drop/reallocate the memory region +with the actual chameleon table size. + +Co-developed-by: Jorge Sanjuan Garcia +Signed-off-by: Jorge Sanjuan Garcia +Signed-off-by: Javier Rodriguez +Signed-off-by: Johannes Thumshirn +Link: https://lore.kernel.org/r/20230411083329.4506-4-jth@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/mcb/mcb-lpc.c | 35 +++++++++++++++++++++++++++++++---- + 1 file changed, 31 insertions(+), 4 deletions(-) + +diff --git a/drivers/mcb/mcb-lpc.c b/drivers/mcb/mcb-lpc.c +index 506676754538b..d513d61f4ba84 100644 +--- a/drivers/mcb/mcb-lpc.c ++++ b/drivers/mcb/mcb-lpc.c +@@ -23,7 +23,7 @@ static int mcb_lpc_probe(struct platform_device *pdev) + { + struct resource *res; + struct priv *priv; +- int ret = 0; ++ int ret = 0, table_size; + + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) +@@ -58,16 +58,43 @@ static int mcb_lpc_probe(struct platform_device *pdev) + + ret = chameleon_parse_cells(priv->bus, priv->mem->start, priv->base); + if (ret < 0) { +- mcb_release_bus(priv->bus); +- return ret; ++ goto out_mcb_bus; + } + +- dev_dbg(&pdev->dev, "Found %d cells\n", ret); ++ table_size = ret; ++ ++ if (table_size < CHAM_HEADER_SIZE) { ++ /* Release the previous resources */ ++ devm_iounmap(&pdev->dev, priv->base); ++ devm_release_mem_region(&pdev->dev, priv->mem->start, resource_size(priv->mem)); ++ ++ /* Then, allocate it again with the actual chameleon table size */ ++ res = devm_request_mem_region(&pdev->dev, priv->mem->start, ++ table_size, ++ KBUILD_MODNAME); ++ if (!res) { ++ dev_err(&pdev->dev, "Failed to request PCI memory\n"); ++ ret = -EBUSY; ++ goto out_mcb_bus; ++ } ++ ++ priv->base = devm_ioremap(&pdev->dev, priv->mem->start, table_size); ++ if (!priv->base) { ++ dev_err(&pdev->dev, "Cannot ioremap\n"); ++ ret = -ENOMEM; ++ goto out_mcb_bus; ++ } ++ ++ platform_set_drvdata(pdev, priv); ++ } + + mcb_bus_add_devices(priv->bus); + + return 0; + ++out_mcb_bus: ++ mcb_release_bus(priv->bus); ++ return ret; + } + + static int mcb_lpc_remove(struct platform_device *pdev) +-- +2.42.0 + diff --git a/queue-5.10/mcb-return-actual-parsed-size-when-reading-chameleon.patch b/queue-5.10/mcb-return-actual-parsed-size-when-reading-chameleon.patch new file mode 100644 index 00000000000..da6f57c53c5 --- /dev/null +++ b/queue-5.10/mcb-return-actual-parsed-size-when-reading-chameleon.patch @@ -0,0 +1,81 @@ +From c962eb115cec6c6aaa32f35584bf477f8c4e7546 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 11 Apr 2023 10:33:27 +0200 +Subject: mcb: Return actual parsed size when reading chameleon table +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Rodríguez Barbarin, José Javier + +[ Upstream commit a889c276d33d333ae96697510f33533f6e9d9591 ] + +The function chameleon_parse_cells() returns the number of cells +parsed which has an undetermined size. This return value is only +used for error checking but the number of cells is never used. + +Change return value to be number of bytes parsed to allow for +memory management improvements. + +Co-developed-by: Jorge Sanjuan Garcia +Signed-off-by: Jorge Sanjuan Garcia +Signed-off-by: Javier Rodriguez +Signed-off-by: Johannes Thumshirn +Link: https://lore.kernel.org/r/20230411083329.4506-2-jth@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/mcb/mcb-parse.c | 15 ++++++++++----- + 1 file changed, 10 insertions(+), 5 deletions(-) + +diff --git a/drivers/mcb/mcb-parse.c b/drivers/mcb/mcb-parse.c +index c41cbacc75a2c..656b6b71c7682 100644 +--- a/drivers/mcb/mcb-parse.c ++++ b/drivers/mcb/mcb-parse.c +@@ -128,7 +128,7 @@ static void chameleon_parse_bar(void __iomem *base, + } + } + +-static int chameleon_get_bar(char __iomem **base, phys_addr_t mapbase, ++static int chameleon_get_bar(void __iomem **base, phys_addr_t mapbase, + struct chameleon_bar **cb) + { + struct chameleon_bar *c; +@@ -177,12 +177,13 @@ int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase, + { + struct chameleon_fpga_header *header; + struct chameleon_bar *cb; +- char __iomem *p = base; ++ void __iomem *p = base; + int num_cells = 0; + uint32_t dtype; + int bar_count; + int ret; + u32 hsize; ++ u32 table_size; + + hsize = sizeof(struct chameleon_fpga_header); + +@@ -237,12 +238,16 @@ int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase, + num_cells++; + } + +- if (num_cells == 0) +- num_cells = -EINVAL; ++ if (num_cells == 0) { ++ ret = -EINVAL; ++ goto free_bar; ++ } + ++ table_size = p - base; ++ pr_debug("%d cell(s) found. Chameleon table size: 0x%04x bytes\n", num_cells, table_size); + kfree(cb); + kfree(header); +- return num_cells; ++ return table_size; + + free_bar: + kfree(cb); +-- +2.42.0 + diff --git a/queue-5.10/selftests-ftrace-add-new-test-case-which-checks-non-.patch b/queue-5.10/selftests-ftrace-add-new-test-case-which-checks-non-.patch new file mode 100644 index 00000000000..ab9c01ba375 --- /dev/null +++ b/queue-5.10/selftests-ftrace-add-new-test-case-which-checks-non-.patch @@ -0,0 +1,47 @@ +From 1d630d5e51f4d48d5135a94e9374cf7521009c6b Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 20 Oct 2023 13:42:50 +0300 +Subject: selftests/ftrace: Add new test case which checks non unique symbol + +From: Francis Laniel + +[ Upstream commit 03b80ff8023adae6780e491f66e932df8165e3a0 ] + +If name_show() is non unique, this test will try to install a kprobe on this +function which should fail returning EADDRNOTAVAIL. +On kernel where name_show() is not unique, this test is skipped. + +Link: https://lore.kernel.org/all/20231020104250.9537-3-flaniel@linux.microsoft.com/ + +Cc: stable@vger.kernel.org +Signed-off-by: Francis Laniel +Acked-by: Masami Hiramatsu (Google) +Signed-off-by: Masami Hiramatsu (Google) +Signed-off-by: Sasha Levin +--- + .../ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc | 13 +++++++++++++ + 1 file changed, 13 insertions(+) + create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc + +diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc +new file mode 100644 +index 0000000000000..bc9514428dbaf +--- /dev/null ++++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc +@@ -0,0 +1,13 @@ ++#!/bin/sh ++# SPDX-License-Identifier: GPL-2.0 ++# description: Test failure of registering kprobe on non unique symbol ++# requires: kprobe_events ++ ++SYMBOL='name_show' ++ ++# We skip this test on kernel where SYMBOL is unique or does not exist. ++if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}" /proc/kallsyms)" -le '1' ]; then ++ exit_unsupported ++fi ++ ++! echo "p:test_non_unique ${SYMBOL}" > kprobe_events +-- +2.42.0 + diff --git a/queue-5.10/series b/queue-5.10/series new file mode 100644 index 00000000000..99a03ee8336 --- /dev/null +++ b/queue-5.10/series @@ -0,0 +1,3 @@ +selftests-ftrace-add-new-test-case-which-checks-non-.patch +mcb-return-actual-parsed-size-when-reading-chameleon.patch +mcb-lpc-reallocate-memory-region-to-avoid-memory-ove.patch