vti4: Fix a ipip packet processing bug in 'IPCOMP' virtual tunnel
Subsystems (25)
Sasha Levin
maintainerPATCH 10/65 IB/{hfi1, qib}: Fix WC.byte_len calculation for UD_SEND_WITH_IMM
In reply to Sasha LevinFrom: Brian Welty <[email protected]>
[ Upstream commit 904bba211acc2112fdf866e5a2bc6cd9ecd0de1b ]
The work completion length for a receiving a UD send with immediate is short by 4 bytes causing application using this opcode to fail.
The UD receive logic incorrectly subtracts 4 bytes for immediate value. These bytes are already included in header length and are used to calculate header/payload split, so the result is these 4 bytes are subtracted twice, once when the header length subtracted from the overall length and once again in the UD opcode specific path.
Remove the extra subtraction when handling the opcode.
--- drivers/infiniband/hw/hfi1/ud.c | 1 - drivers/infiniband/hw/qib/qib_ud.c | 1 - 2 files changed, 2 deletions(-)
drivers/infiniband/hw/hfi1/ud.c +0 -1
@@ -980,7 +980,6 @@ void hfi1_ud_rcv(struct hfi1_packet *packet) opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) { wc.ex.imm_data = packet->ohdr->u.ud.imm_data; wc.wc_flags =IB_WC_WITH_IMM ; - tlen -=sizeof (u32); } else if (opcode == IB_OPCODE_UD_SEND_ONLY) { wc.ex.imm_data =0 ; wc.wc_flags =0 ;
drivers/infiniband/hw/qib/qib_ud.c +0 -1
@@ -513,7 +513,6 @@ void qib_ud_rcv(struct qib_ibport *ibp, struct ib_header *hdr, opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) { wc.ex.imm_data = ohdr->u.ud.imm_data; wc.wc_flags =IB_WC_WITH_IMM ; - tlen -=sizeof (u32); } else if (opcode == IB_OPCODE_UD_SEND_ONLY) { wc.ex.imm_data =0 ; wc.wc_flags =0 ;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 11/65 iommu/amd: Call free_iova_fast with pfn in map_sg
In reply to Sasha LevinFrom: Jerry Snitselaar <[email protected]>
[ Upstream commit 51d8838d66d3249508940d8f59b07701f2129723 ]
In the error path of map_sg, free_iova_fast is being called with address instead of the pfn. This results in a bad value getting into the rcache, and can result in hitting a BUG_ON when iova_magazine_free_pfns is called.
--- drivers/iommu/amd_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/amd_iommu.c +1 -1
@@ -2554,7 +2554,7 @@ static int map_sg(struct device *dev, struct scatterlist *sglist, } out_free_iova: -free_iova_fast (&dma_dom->iovad, address, npages); +free_iova_fast (&dma_dom->iovad, address >>PAGE_SHIFT , npages); out_err:return 0 ;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 12/65 iommu/amd: Unmap all mapped pages in error path of map_sg
In reply to Sasha LevinFrom: Jerry Snitselaar <[email protected]>
[ Upstream commit f1724c0883bb0ce93b8dcb94b53dcca3b75ac9a7 ]
In the error path of map_sg there is an incorrect if condition for breaking out of the loop that searches the scatterlist for mapped pages to unmap. Instead of breaking out of the loop once all the pages that were mapped have been unmapped, it will break out of the loop after it has unmapped 1 page. Fix the condition, so it breaks out of the loop only after all the mapped pages have been unmapped.
--- drivers/iommu/amd_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/amd_iommu.c +1 -1
@@ -2548,7 +2548,7 @@ static int map_sg(struct device *dev, struct scatterlist *sglist, bus_addr = address + s->dma_address + (j <<PAGE_SHIFT );iommu_unmap_page (domain, bus_addr,PAGE_SIZE ); -if (--mapped_pages) +if (--mapped_pages ==0 ) goto out_free_iova; } }
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 14/65 ipvs: Fix signed integer overflow when setsockopt timeout
In reply to Sasha LevinFrom: ZhangXiaoxu <[email protected]>
[ Upstream commit 53ab60baa1ac4f20b080a22c13b77b6373922fd7 ]
There is a UBSAN bug report as below:
UBSAN: Undefined behaviour in net/netfilter/ipvs/ip_vs_ctl.c:2227:21
signed integer overflow:
-2147483647 * 1000 cannot be represented in type 'int'
Reproduce program:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#define IPPROTO_IP 0
#define IPPROTO_RAW 255
#define IP_VS_BASE_CTL (64+1024+64)
#define IP_VS_SO_SET_TIMEOUT (IP_VS_BASE_CTL+10)
/* The argument to IP_VS_SO_GET_TIMEOUT */
struct ipvs_timeout_t {
int tcp_timeout;
int tcp_fin_timeout;
int udp_timeout;
};
int main() {
int ret = -1;
int sockfd = -1;
struct ipvs_timeout_t to;
sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
if (sockfd == -1) {
printf("socket init error\n");
return -1;
}
to.tcp_timeout = -2147483647;
to.tcp_fin_timeout = -2147483647;
to.udp_timeout = -2147483647;
ret = setsockopt(sockfd,
IPPROTO_IP,
IP_VS_SO_SET_TIMEOUT,
(char *)(&to),
sizeof(to));
printf("setsockopt return %d\n", ret);
return ret;
}Return -EINVAL if the timeout value is negative or max than 'INT_MAX / HZ'.
--- net/netfilter/ipvs/ip_vs_ctl.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/netfilter/ipvs/ip_vs_ctl.c +12 -0
@@ -2220,6 +2220,18 @@ static int ip_vs_set_timeout(struct netns_ipvs *ipvs, struct ip_vs_timeout_user u->tcp_fin_timeout, u->udp_timeout); +#ifdef CONFIG_IP_VS_PROTO_TCP +if (u->tcp_timeout <0 || u->tcp_timeout > (INT_MAX /HZ ) || + u->tcp_fin_timeout <0 || u->tcp_fin_timeout > (INT_MAX /HZ )) { +return -EINVAL ; + } +#endif + +#ifdef CONFIG_IP_VS_PROTO_UDP +if (u->udp_timeout <0 || u->udp_timeout > (INT_MAX /HZ )) +return -EINVAL ; +#endif +#ifdef CONFIG_IP_VS_PROTO_TCP if (u->tcp_timeout) { pd =ip_vs_proto_data_get (ipvs,IPPROTO_TCP );
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 15/65 iommu/amd: Fix IOMMU page flush when detach device from a domain
In reply to Sasha LevinFrom: Suravee Suthikulpanit <[email protected]>
[ Upstream commit 9825bd94e3a2baae1f4874767ae3a7d4c049720e ]
When a VM is terminated, the VFIO driver detaches all pass-through devices from VFIO domain by clearing domain id and page table root pointer from each device table entry (DTE), and then invalidates the DTE. Then, the VFIO driver unmap pages and invalidate IOMMU pages.
Currently, the IOMMU driver keeps track of which IOMMU and how many devices are attached to the domain. When invalidate IOMMU pages, the driver checks if the IOMMU is still attached to the domain before issuing the invalidate page command.
However, since VFIO has already detached all devices from the domain, the subsequent INVALIDATE_IOMMU_PAGES commands are being skipped as there is no IOMMU attached to the domain. This results in data corruption and could cause the PCI device to end up in indeterministic state.
Fix this by invalidate IOMMU pages when detach a device, and before decrementing the per-domain device reference counts.
--- drivers/iommu/amd_iommu.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/iommu/amd_iommu.c +11 -4
@@ -1922,16 +1922,13 @@ static void do_attach(struct iommu_dev_data *dev_data,static void do_detach (struct iommu_dev_data *dev_data) { +struct protection_domain *domain = dev_data->domain;struct amd_iommu *iommu;u16 alias; iommu = amd_iommu_rlookup_table[dev_data->devid]; alias = dev_data->alias; -/* decrease reference counters */ - dev_data->domain->dev_iommu[iommu->index] -=1 ; - dev_data->domain->dev_cnt -=1 ; -/* Update data structures */ dev_data->domain =NULL ;list_del (&dev_data->list);
@@ -1941,6 +1938,16 @@ static void do_detach(struct iommu_dev_data *dev_data)/* Flush the DTE entry */ device_flush_dte (dev_data); + +/* Flush IOTLB */ +domain_flush_tlb_pde (domain); + +/* Wait for the flushes to finish */ +domain_flush_complete (domain); + +/* decrease reference counters - needs to happen after the flushes */ + domain->dev_iommu[iommu->index] -=1 ; + domain->dev_cnt -=1 ; }/*
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 16/65 clk: ti: Fix error handling in ti_clk_parse_divider_data()
In reply to Sasha LevinFrom: Dan Carpenter <[email protected]>
[ Upstream commit 303aef8b84272d73999a3207dd05bbe10ed89dc5 ]
The ti_clk_parse_divider_data() function is only called from _get_div_table_from_setup(). That function doesn't look at the return value but instead looks at the "*table" pointer. In this case, if the kcalloc() fails then *table is NULL (which means success). It should instead be an error pointer.
The ti_clk_parse_divider_data() function has two callers. One checks for errors and the other doesn't. I have fixed it so now both handle errors.
--- drivers/clk/ti/divider.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/clk/ti/divider.c +10 -1
@@ -367,8 +367,10 @@ int ti_clk_parse_divider_data(int *div_table, int num_dividers, int max_div, num_dividers = i; tmp =kcalloc (valid_div +1 ,sizeof (*tmp),GFP_KERNEL ); -if (!tmp) +if (!tmp) { + *table =ERR_PTR (-ENOMEM );return -ENOMEM ; + } valid_div =0 ; *width =0 ;
@@ -403,6 +405,7 @@ struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup) {struct clk_omap_divider *div;struct clk_omap_reg *reg; +int ret;if (!setup)return NULL ;
@@ -422,6 +425,12 @@ struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup) div->flags |=CLK_DIVIDER_POWER_OF_TWO ; div->table =_get_div_table_from_setup (setup, &div->width); +if (IS_ERR (div->table)) { + ret =PTR_ERR (div->table); +kfree (div); +return ERR_PTR (ret); + } + div->shift = setup->bit_shift; div->latch = -EINVAL ;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 17/65 clk: qcom: gcc: Use active only source for CPUSS clocks
In reply to Sasha LevinFrom: Taniya Das <[email protected]>
[ Upstream commit 9ff1a3b4912528f853048ccd9757ba6a2cc75557 ]
The clocks of the CPUSS such as "gcc_cpuss_ahb_clk_src" is a CRITICAL clock and needs to vote on the active only source of XO, so as to keep the vote as long as CPUSS is active. Similar rbcpr_clk_src is also has the same requirement.
--- drivers/clk/qcom/gcc-sdm845.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/clk/qcom/gcc-sdm845.c +10 -4
@@ -131,8 +131,8 @@ static const char * const gcc_parent_names_6[] = { "core_bi_pll_test_se", }; -static const char *const gcc_parent_names_7[] = { -"bi_tcxo" , +static const char *const gcc_parent_names_7_ao[] = { +"bi_tcxo_ao" ,"gpll0" ,"gpll0_out_even" ,"core_bi_pll_test_se" ,
@@ -144,6 +144,12 @@ static const char * const gcc_parent_names_8[] = { "core_bi_pll_test_se", }; +static const char *const gcc_parent_names_8_ao[] = { +"bi_tcxo_ao" , +"gpll0" , +"core_bi_pll_test_se" , +}; +static const struct parent_map gcc_parent_map_10[] = { {P_BI_TCXO ,0 }, {P_GPLL0_OUT_MAIN ,1 },
@@ -226,7 +232,7 @@ static struct clk_rcg2 gcc_cpuss_ahb_clk_src = { .freq_tbl = ftbl_gcc_cpuss_ahb_clk_src, .clkr.hw.init = &(struct clk_init_data ){ .name ="gcc_cpuss_ahb_clk_src" , - .parent_names = gcc_parent_names_7, + .parent_names = gcc_parent_names_7_ao, .num_parents =4 , .ops = &clk_rcg2_ops, },
@@ -245,7 +251,7 @@ static struct clk_rcg2 gcc_cpuss_rbcpr_clk_src = { .freq_tbl = ftbl_gcc_cpuss_rbcpr_clk_src, .clkr.hw.init = &(struct clk_init_data ){ .name ="gcc_cpuss_rbcpr_clk_src" , - .parent_names = gcc_parent_names_8, + .parent_names = gcc_parent_names_8_ao, .num_parents =3 , .ops = &clk_rcg2_ops, },
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 20/65 IB/ipoib: Fix for use-after-free in ipoib_cm_tx_start
In reply to Sasha LevinFrom: Feras Daoud <[email protected]>
[ Upstream commit 6ab4aba00f811a5265acc4d3eb1863bb3ca60562 ]
The following BUG was reported by kasan:
BUG: KASAN: use-after-free in ipoib_cm_tx_start+0x430/0x1390 [ib_ipoib]
Read of size 80 at addr ffff88034c30bcd0 by task kworker/u16:1/24020
Workqueue: ipoib_wq ipoib_cm_tx_start [ib_ipoib]
Call Trace:
dump_stack+0x9a/0xeb
print_address_description+0xe3/0x2e0
kasan_report+0x18a/0x2e0
? ipoib_cm_tx_start+0x430/0x1390 [ib_ipoib]
memcpy+0x1f/0x50
ipoib_cm_tx_start+0x430/0x1390 [ib_ipoib]
? kvm_clock_read+0x1f/0x30
? ipoib_cm_skb_reap+0x610/0x610 [ib_ipoib]
? __lock_is_held+0xc2/0x170
? process_one_work+0x880/0x1960
? process_one_work+0x912/0x1960
process_one_work+0x912/0x1960
? wq_pool_ids_show+0x310/0x310
? lock_acquire+0x145/0x440
worker_thread+0x87/0xbb0
? process_one_work+0x1960/0x1960
kthread+0x314/0x3d0
? kthread_create_worker_on_cpu+0xc0/0xc0
ret_from_fork+0x3a/0x50
Allocated by task 0:
kasan_kmalloc+0xa0/0xd0
kmem_cache_alloc_trace+0x168/0x3e0
path_rec_create+0xa2/0x1f0 [ib_ipoib]
ipoib_start_xmit+0xa98/0x19e0 [ib_ipoib]
dev_hard_start_xmit+0x159/0x8d0
sch_direct_xmit+0x226/0xb40
__dev_queue_xmit+0x1d63/0x2950
neigh_update+0x889/0x1770
arp_process+0xc47/0x21f0
arp_rcv+0x462/0x760
__netif_receive_skb_core+0x1546/0x2da0
netif_receive_skb_internal+0xf2/0x590
napi_gro_receive+0x28e/0x390
ipoib_ib_handle_rx_wc_rss+0x873/0x1b60 [ib_ipoib]
ipoib_rx_poll_rss+0x17d/0x320 [ib_ipoib]
net_rx_action+0x427/0xe30
__do_softirq+0x28e/0xc42
Freed by task 26680:
__kasan_slab_free+0x11d/0x160
kfree+0xf5/0x360
ipoib_flush_paths+0x532/0x9d0 [ib_ipoib]
ipoib_set_mode_rss+0x1ad/0x560 [ib_ipoib]
set_mode+0xc8/0x150 [ib_ipoib]
kernfs_fop_write+0x279/0x440
__vfs_write+0xd8/0x5c0
vfs_write+0x15e/0x470
ksys_write+0xb8/0x180
do_syscall_64+0x9b/0x420
entry_SYSCALL_64_after_hwframe+0x49/0xbe
The buggy address belongs to the object at ffff88034c30bcc8
which belongs to the cache kmalloc-512 of size 512
The buggy address is located 8 bytes inside of
512-byte region [ffff88034c30bcc8, ffff88034c30bec8)
The buggy address belongs to the page:The following race between change mode and xmit flow is the reason for this use-after-free:
Change mode Send packet 1 to GID XX Send packet 2 to GID XX
| | |
start | |
| | |
| | |
| Create new path for GID XX |
| and update neigh path |
| | |
| | |
| | |
flush_paths | |
| |
queue_work(cm.start_task) |
| Path for GID XX not found
| create new path
|
| start_task runs with old
released path
There is no locking to protect the lifetime of the path through the ipoib_cm_tx struct, so delete it entirely and always use the newly looked up path under the priv->lock.
--- drivers/infiniband/ulp/ipoib/ipoib.h | 1 - drivers/infiniband/ulp/ipoib/ipoib_cm.c | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib.h +0 -1
@@ -248,7 +248,6 @@ struct ipoib_cm_tx {struct list_head list;struct net_device *dev;struct ipoib_neigh *neigh; -struct ipoib_path *path;struct ipoib_tx_buf *tx_ring;unsigned int tx_head;unsigned int tx_tail;
drivers/infiniband/ulp/ipoib/ipoib_cm.c +1 -2
@@ -1312,7 +1312,6 @@ struct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path neigh->cm = tx; tx->neigh = neigh; - tx->path = path; tx->dev = dev;list_add (&tx->list, &priv->cm.start_list);set_bit (IPOIB_FLAG_INITIALIZED , &tx->flags);
@@ -1371,7 +1370,7 @@ static void ipoib_cm_tx_start(struct work_struct *work) neigh->daddr + QPN_AND_OPTIONS_OFFSET); goto free_neigh; } -memcpy (&pathrec, &p->path->pathrec,sizeof (pathrec)); +memcpy (&pathrec, &path->pathrec,sizeof (pathrec));spin_unlock_irqrestore (&priv->lock, flags);netif_tx_unlock_bh (dev);
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 21/65 selftests: cpu-hotplug: fix case where CPUs offline > CPUs present
In reply to Sasha LevinFrom: Colin Ian King <[email protected]>
[ Upstream commit 2b531b6137834a55857a337ac17510d6436b6fbb ]
The cpu-hotplug test assumes that we can offline the maximum CPU as described by /sys/devices/system/cpu/offline. However, in the case where the number of CPUs exceeds like kernel configuration then the offline count can be greater than the present count and we end up trying to test the offlining of a CPU that is not available to offline. Fix this by testing the maximum present CPU instead.
Also, the test currently offlines the CPU and does not online it, so fix this by onlining the CPU after the test.
--- .../selftests/cpu-hotplug/cpu-on-off-test.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh +10 -3
@@ -37,6 +37,10 @@ prerequisite() exit $ksft_skip fi + present_cpus=`cat $SYSFS/devices/system/cpu/present` + present_max=${present_cpus##*-} + echo "present_cpus = $present_cpus present_max = $present_max" + echo -e "\t Cpus in online state: $online_cpus" offline_cpus=`cat $SYSFS/devices/system/cpu/offline`
@@ -151,6 +155,8 @@ online_cpus=0 online_max=0 offline_cpus=0 offline_max=0 +present_cpus=0 +present_max=0 while getopts e:ahp: opt; do case $opt in
@@ -190,9 +196,10 @@ if [ $allcpus -eq 0 ]; then online_cpu_expect_success $online_max if [[ $offline_cpus -gt 0 ]]; then - echo -e "\t offline to online to offline: cpu $offline_max" - online_cpu_expect_success $offline_max - offline_cpu_expect_success $offline_max + echo -e "\t offline to online to offline: cpu $present_max" + online_cpu_expect_success $present_max + offline_cpu_expect_success $present_max + online_cpu $present_max fi exit 0 else
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 35/65 gpio: vf610: Mask all GPIO interrupts
In reply to Sasha LevinFrom: Andrew Lunn <[email protected]>
[ Upstream commit 7ae710f9f8b2cf95297e7bbfe1c09789a7dc43d4 ]
On SoC reset all GPIO interrupts are disable. However, if kexec is used to boot into a new kernel, the SoC does not experience a reset. Hence GPIO interrupts can be left enabled from the previous kernel. It is then possible for the interrupt to fire before an interrupt handler is registered, resulting in the kernel complaining of an "unexpected IRQ trap", the interrupt is never cleared, and so fires again, resulting in an interrupt storm.
Disable all GPIO interrupts before registering the GPIO IRQ chip.
--- drivers/gpio/gpio-vf610.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpio/gpio-vf610.c +5 -0
@@ -259,6 +259,7 @@ static int vf610_gpio_probe(struct platform_device *pdev)struct vf610_gpio_port *port;struct resource *iores;struct gpio_chip *gc; +int i;int ret; port =devm_kzalloc (&pdev->dev,sizeof (*port),GFP_KERNEL );
@@ -298,6 +299,10 @@ static int vf610_gpio_probe(struct platform_device *pdev)if (ret <0 )return ret; +/* Mask all GPIO interrupts */ +for (i =0 ; i < gc->ngpio; i++) +vf610_gpio_writel (0 , port->base +PORT_PCR (i)); +/* Clear the interrupt status register for all GPIO's */ vf610_gpio_writel (~0 , port->base +PORT_ISFR );
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 36/65 selftests: net: use LDLIBS instead of LDFLAGS
In reply to Sasha LevinFrom: Fathi Boudra <fathi.boudra at linaro.org>
[ Upstream commit 870f193d48c25a97d61a8e6c04e3c29a2c606850 ]
reuseport_bpf_numa fails to build due to undefined reference errors:
aarch64-linaro-linux-gcc
--sysroot=/build/tmp-rpb-glibc/sysroots/hikey -Wall
-Wl,--no-as-needed -O2 -g -I../../../../usr/include/ -Wl,-O1
-Wl,--hash-style=gnu -Wl,--as-needed -lnuma reuseport_bpf_numa.c
-o /build/tmp-rpb-glibc/work/hikey-linaro-linux/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/net/reuseport_bpf_numa /tmp/ccfUuExT.o: In function `send_from_node':
/build/tmp-rpb-glibc/work/hikey-linaro-linux/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/net/reuseport_bpf_numa.c:138:
undefined reference to `numa_run_on_node'
/tmp/ccfUuExT.o: In function `main':
/build/tmp-rpb-glibc/work/hikey-linaro-linux/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/net/reuseport_bpf_numa.c:230:
undefined reference to `numa_available' /build/tmp-rpb-glibc/work/hikey-linaro-linux/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/net/reuseport_bpf_numa.c:233:
undefined reference to `numa_max_node'
It's GNU Make and linker specific.
The default Makefile rule looks like:
$(CC) $(CFLAGS) $(LDFLAGS) $@ $^ $(LDLIBS)
When linking is done by gcc itself, no issue, but when it needs to be passed to proper ld, only LDLIBS follows and then ld cannot know what libs to link with.
More detail:
https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
LDFLAGS
Extra flags to give to compilers when they are supposed to invoke the linker, ‘ld’, such as -L. Libraries (-lfoo) should be added to the LDLIBS variable instead.
LDLIBS
Library flags or names given to compilers when they are supposed to invoke the linker, ‘ld’. LOADLIBES is a deprecated (but still supported) alternative to LDLIBS. Non-library linker flags, such as -L, should go in the LDFLAGS variable.
https://lkml.org/lkml/2010/2/10/362
tools/perf: libraries must come after objects
Link order matters, use LDLIBS instead of LDFLAGS to properly link against libnuma.
--- tools/testing/selftests/net/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/Makefile +1 -1
@@ -18,6 +18,6 @@ TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls KSFT_KHDR_INSTALL := 1 include ../lib.mk -$(OUTPUT)/reuseport_bpf_numa: LDFLAGS += -lnuma +$(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma $(OUTPUT)/tcp_mmap: LDFLAGS += -lpthread $(OUTPUT)/tcp_inq: LDFLAGS += -lpthread
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 37/65 selftests: timers: use LDLIBS instead of LDFLAGS
In reply to Sasha LevinFrom: Fathi Boudra <fathi.boudra at linaro.org>
[ Upstream commit 7d4e591bc051d3382c45caaa2530969fb42ed23d ]
posix_timers fails to build due to undefined reference errors:
aarch64-linaro-linux-gcc --sysroot=/build/tmp-rpb-glibc/sysroots/hikey
-O2 -pipe -g -feliminate-unused-debug-types -O3 -Wl,-no-as-needed -Wall
-DKTEST -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -lrt -lpthread
posix_timers.c
-o /build/tmp-rpb-glibc/work/hikey-linaro-linux/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/timers/posix_timers /tmp/cc1FTZzT.o: In function `check_timer_create':
/usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/timers/posix_timers.c:157:
undefined reference to `timer_create' /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/timers/posix_timers.c:170:
undefined reference to `timer_settime'
collect2: error: ld returned 1 exit status
It's GNU Make and linker specific.
The default Makefile rule looks like:
$(CC) $(CFLAGS) $(LDFLAGS) $@ $^ $(LDLIBS)
When linking is done by gcc itself, no issue, but when it needs to be passed to proper ld, only LDLIBS follows and then ld cannot know what libs to link with.
More detail:
https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
LDFLAGS
Extra flags to give to compilers when they are supposed to invoke the linker, ‘ld’, such as -L. Libraries (-lfoo) should be added to the LDLIBS variable instead.
LDLIBS
Library flags or names given to compilers when they are supposed to invoke the linker, ‘ld’. LOADLIBES is a deprecated (but still supported) alternative to LDLIBS. Non-library linker flags, such as -L, should go in the LDFLAGS variable.
https://lkml.org/lkml/2010/2/10/362
tools/perf: libraries must come after objects
Link order matters, use LDLIBS instead of LDFLAGS to properly link against libpthread.
--- tools/testing/selftests/timers/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/timers/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS += -O3 -Wl,-no-as-needed -Wall -LDFLAGS += -lrt -lpthread -lm +LDLIBS += -lrt -lpthread -lm # these are all "safe" tests that don't modify # system time or require escalated privileges
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 44/65 scsi: libfc: free skb when receiving invalid flogi resp
In reply to Sasha LevinFrom: Ming Lu <[email protected]>
[ Upstream commit 5d8fc4a9f0eec20b6c07895022a6bea3fb6dfb38 ]
The issue to be fixed in this commit is when libfc found it received a invalid FLOGI response from FC switch, it would return without freeing the fc frame, which is just the skb data. This would cause memory leak if FC switch keeps sending invalid FLOGI responses.
This fix is just to make it execute fc_frame_free(fp) before returning from function fc_lport_flogi_resp.
--- drivers/scsi/libfc/fc_lport.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/libfc/fc_lport.c +3 -3
@@ -1726,14 +1726,14 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp, fc_frame_payload_op(fp) != ELS_LS_ACC) {FC_LPORT_DBG (lport,"FLOGI not accepted or bad response\n" );fc_lport_error (lport, fp); - goto err; + goto out; } flp =fc_frame_payload_get (fp,sizeof (*flp));if (!flp) {FC_LPORT_DBG (lport,"FLOGI bad response\n" );fc_lport_error (lport, fp); - goto err; + goto out; } mfs = ntohs(flp->fl_csp.sp_bb_data) &
@@ -1743,7 +1743,7 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,FC_LPORT_DBG (lport,"FLOGI bad mfs:%hu response, " "lport->mfs:%hu\n" , mfs, lport->mfs);fc_lport_error (lport, fp); - goto err; + goto out; }if (mfs <= lport->mfs) {
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 45/65 scsi: scsi_debug: fix write_same with virtual_gb problem
In reply to Sasha LevinFrom: Douglas Gilbert <[email protected]>
[ Upstream commit 40d07b523cf434f252b134c86b1f8f2d907ffb0b ]
The WRITE SAME(10) and (16) implementations didn't take account of the buffer wrap required when the virtual_gb parameter is greater than 0.
Fix that and rename the fake_store() function to lba2fake_store() to lessen confusion with the global fake_storep pointer. Bump version date.
Tested by: Bart Van Assche <[email protected]>
--- drivers/scsi/scsi_debug.c | 41 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-)
drivers/scsi/scsi_debug.c +21 -20
@@ -62,7 +62,7 @@/* make sure inq_product_rev string corresponds to this version */ #define SDEBUG_VERSION "0188"/* format to fit INQUIRY revision field */ -static const char *sdebug_version_date ="20180128" ; +static const char *sdebug_version_date ="20190125" ;#define MY_NAME "scsi_debug"
@@ -735,7 +735,7 @@ static inline bool scsi_debug_lbp(void) (sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10); } -static void *fake_store (unsigned long long lba) +static void *lba2fake_store (unsigned long long lba) { lba =do_div (lba, sdebug_store_sectors);
@@ -2514,8 +2514,8 @@ static int do_device_access(struct scsi_cmnd *scmd, u32 sg_skip, u64 lba,return ret; } -/* If fake_store(lba,num) compares equal to arr(num), then copy top half of -* arr into fake_store(lba,num) and return true. If comparison fails then +/* If lba2fake_store(lba,num) compares equal to arr(num), then copy top half of +* arr into lba2fake_store(lba,num) and return true. If comparison fails then * return false. */ static bool comp_write_worker (u64 lba,u32 num,const u8 *arr) {
@@ -2643,7 +2643,7 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec,if (sdt->app_tag ==cpu_to_be16 (0xffff ))continue ; - ret =dif_verify (sdt,fake_store (sector), sector, ei_lba); + ret =dif_verify (sdt,lba2fake_store (sector), sector, ei_lba);if (ret) { dif_errors++;return ret;
@@ -3261,10 +3261,12 @@ static int resp_write_scat(struct scsi_cmnd *scp,static int resp_write_same (struct scsi_cmnd *scp,u64 lba,u32 num,u32 ei_lba,bool unmap,bool ndob) { +int ret;unsigned long iflags;unsigned long long i; -int ret; -u64 lba_off; +u32 lb_size = sdebug_sector_size; +u64 block, lbaa; +u8 *fs1p; ret =check_device_access_params (scp, lba, num);if (ret)
@@ -3276,31 +3278,30 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,unmap_region (lba, num); goto out; } - - lba_off = lba * sdebug_sector_size; + lbaa = lba; + block =do_div (lbaa, sdebug_store_sectors);/* if ndob then zero 1 logical block, else fetch 1 logical block */ + fs1p = fake_storep + (block * lb_size);if (ndob) { -memset (fake_storep + lba_off,0 , sdebug_sector_size); +memset (fs1p,0 , lb_size); ret =0 ; }else - ret =fetch_to_dev_buffer (scp, fake_storep + lba_off, - sdebug_sector_size); + ret =fetch_to_dev_buffer (scp, fs1p, lb_size);if (-1 == ret) {write_unlock_irqrestore (&atomic_rw, iflags);return DID_ERROR <<16 ; - }else if (sdebug_verbose && !ndob && (ret < sdebug_sector_size)) + }else if (sdebug_verbose && !ndob && (ret < lb_size))sdev_printk (KERN_INFO , scp->device,"%s: %s: lb size=%u, IO sent=%d bytes\n" , - my_name,"write same" , - sdebug_sector_size, ret); + my_name,"write same" , lb_size, ret);/* Copy first sector to remaining blocks */ -for (i =1 ; i < num ; i++) -memcpy (fake_storep + ((lba + i) * sdebug_sector_size), - fake_storep + lba_off, - sdebug_sector_size); - +for (i =1 ; i < num ; i++) { + lbaa = lba + i; + block =do_div (lbaa, sdebug_store_sectors); +memmove (fake_storep + (block * lb_size), fs1p, lb_size); + }if (scsi_debug_lbp ())map_region (lba, num); out:
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 46/65 scsi: bnx2fc: Fix error handling in probe()
In reply to Sasha LevinFrom: Dan Carpenter <[email protected]>
[ Upstream commit b2d3492fc591b1fb46b81d79ca1fc44cac6ae0ae ]
There are two issues here. First if cmgr->hba is not set early enough then it leads to a NULL dereference. Second if we don't completely initialize cmgr->io_bdt_pool[] then we end up dereferencing uninitialized pointers.
--- drivers/scsi/bnx2fc/bnx2fc_io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/bnx2fc/bnx2fc_io.c +2 -2
@@ -240,6 +240,7 @@ struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba)return NULL ; } + cmgr->hba = hba; cmgr->free_list =kcalloc (arr_sz,sizeof (*cmgr->free_list),GFP_KERNEL );if (!cmgr->free_list) {
@@ -256,7 +257,6 @@ struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba) goto mem_err; } - cmgr->hba = hba; cmgr->cmds = (struct bnx2fc_cmd **)(cmgr +1 );for (i =0 ; i < arr_sz; i++) {
@@ -295,7 +295,7 @@ struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba)/* Allocate pool of io_bdts - one for each bnx2fc_cmd */ mem_size = num_ios *sizeof (struct io_bdt *); - cmgr->io_bdt_pool =kmalloc (mem_size,GFP_KERNEL ); + cmgr->io_bdt_pool =kzalloc (mem_size,GFP_KERNEL );if (!cmgr->io_bdt_pool) { printk(KERN_ERR PFX "failed to alloc io_bdt_pool\n"); goto mem_err;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 47/65 scsi: 53c700: pass correct "dev" to dma_alloc_attrs()
In reply to Sasha LevinFrom: Dan Carpenter <[email protected]>
[ Upstream commit 8437fcf14deed67e5ad90b5e8abf62fb20f30881 ]
The "hostdata->dev" pointer is NULL here. We set "hostdata->dev = dev;" later in the function and we also use "hostdata->dev" when we call dma_free_attrs() in NCR_700_release().
This bug predates git version control.
--- drivers/scsi/53c700.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/53c700.c +1 -1
@@ -295,7 +295,7 @@ NCR_700_detect(struct scsi_host_template *tpnt,if (tpnt->sdev_attrs ==NULL ) tpnt->sdev_attrs = NCR_700_dev_attrs; - memory =dma_alloc_attrs (hostdata->dev,TOTAL_MEM_SIZE , &pScript, + memory =dma_alloc_attrs (dev,TOTAL_MEM_SIZE , &pScript,GFP_KERNEL ,DMA_ATTR_NON_CONSISTENT );if (memory ==NULL ) {printk (KERN_ERR "53c700: Failed to allocate memory for driver, detaching\n" );
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 48/65 platform/x86: Fix unmet dependency warning for ACPI_CMPC
In reply to Sasha LevinFrom: Sinan Kaya <[email protected]>
[ Upstream commit d58bf90a32a33becec78c3034e781735049fcd25 ]
Add BACKLIGHT_LCD_SUPPORT for ACPI_CMPC to fix the
warning: unmet direct dependencies detected for BACKLIGHT_CLASS_DEVICE.
ACPI_CMPC selects BACKLIGHT_CLASS_DEVICE but BACKLIGHT_CLASS_DEVICE depends on BACKLIGHT_LCD_SUPPORT.
Copy BACKLIGHT_LCD_SUPPORT dependency into ACPI_CMPC to fix
WARNING: unmet direct dependencies detected for BACKLIGHT_CLASS_DEVICE
Depends on [n]: HAS_IOMEM [=y] && BACKLIGHT_LCD_SUPPORT [=n]
Selected by [y]:
- ACPI_CMPC [=y] && X86 [=y] && X86_PLATFORM_DEVICES [=y] && ACPI [=y] && INPUT [=y] && (RFKILL [=n] || RFKILL [=n]=n)
--- drivers/platform/x86/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/platform/x86/Kconfig +1 -0
@@ -856,6 +856,7 @@ config TOSHIBA_WMI config ACPI_CMPC tristate "CMPC Laptop Extras" depends on ACPI && INPUT + depends on BACKLIGHT_LCD_SUPPORT depends on RFKILL || RFKILL=n select BACKLIGHT_CLASS_DEVICE help
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 49/65 platform/x86: Fix unmet dependency warning for SAMSUNG_Q10
In reply to Sasha LevinFrom: Sinan Kaya <[email protected]>
[ Upstream commit 0ee4b5f801b73b83a9fb3921d725f2162fd4a2e5 ]
Add BACKLIGHT_LCD_SUPPORT for SAMSUNG_Q10 to fix the
warning: unmet direct dependencies detected for BACKLIGHT_CLASS_DEVICE.
SAMSUNG_Q10 selects BACKLIGHT_CLASS_DEVICE but BACKLIGHT_CLASS_DEVICE depends on BACKLIGHT_LCD_SUPPORT.
Copy BACKLIGHT_LCD_SUPPORT dependency into SAMSUNG_Q10 to fix:
WARNING: unmet direct dependencies detected for BACKLIGHT_CLASS_DEVICE
Depends on [n]: HAS_IOMEM [=y] && BACKLIGHT_LCD_SUPPORT [=n] Selected by [y]:
- SAMSUNG_Q10 [=y] && X86 [=y] && X86_PLATFORM_DEVICES [=y] && ACPI [=y]
--- drivers/platform/x86/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/platform/x86/Kconfig +1 -0
@@ -1078,6 +1078,7 @@ config INTEL_OAKTRAIL config SAMSUNG_Q10 tristate "Samsung Q10 Extras" depends on ACPI + depends on BACKLIGHT_LCD_SUPPORT select BACKLIGHT_CLASS_DEVICE ---help--- This driver provides support for backlight control on Samsung Q10
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 57/65 x86/kexec: Don't setup EFI info if EFI runtime is not enabled
In reply to Sasha LevinFrom: Kairui Song <[email protected]>
[ Upstream commit 2aa958c99c7fd3162b089a1a56a34a0cdb778de1 ]
Kexec-ing a kernel with "efi=noruntime" on the first kernel's command line causes the following null pointer dereference:
BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 #PF error: [normal kernel read fault] Call Trace: efi_runtime_map_copy+0x28/0x30 bzImage64_load+0x688/0x872 arch_kexec_kernel_image_load+0x6d/0x70 kimage_file_alloc_init+0x13e/0x220 __x64_sys_kexec_file_load+0x144/0x290 do_syscall_64+0x55/0x1a0 entry_SYSCALL_64_after_hwframe+0x44/0xa9
Just skip the EFI info setup if EFI runtime services are not enabled.
[ bp: Massage commit message. ]
--- arch/x86/kernel/kexec-bzimage64.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kernel/kexec-bzimage64.c +3 -0
@@ -167,6 +167,9 @@ setup_efi_state(struct boot_params *params, unsigned long params_load_addr,struct efi_info *current_ei = &boot_params.efi_info;struct efi_info *ei = ¶ms->efi_info; +if (!efi_enabled (EFI_RUNTIME_SERVICES )) +return 0 ; +if (!current_ei->efi_memmap_size)return 0 ;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 58/65 proc: fix /proc/net/* after setns(2)
In reply to Sasha LevinFrom: Alexey Dobriyan <[email protected]>
[ Upstream commit 1fde6f21d90f8ba5da3cb9c54ca991ed72696c43 ]
/proc entries under /proc/net/* can't be cached into dcache because setns(2) can change current net namespace.
--- fs/proc/generic.c | 4 +- fs/proc/internal.h | 1 + fs/proc/proc_net.c | 20 +++ tools/testing/selftests/proc/.gitignore | 1 + tools/testing/selftests/proc/Makefile | 1 + tools/testing/selftests/proc/setns-dcache.c | 129 ++++++++++++++++++++ 6 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/proc/setns-dcache.c
fs/proc/generic.c +3 -1
@@ -256,7 +256,7 @@ struct dentry *proc_lookup_de(struct inode *dir, struct dentry *dentry, inode =proc_get_inode (dir->i_sb, de);if (!inode)return ERR_PTR (-ENOMEM ); -d_set_d_op (dentry, &proc_misc_dentry_ops); +d_set_d_op (dentry, de->proc_dops);return d_splice_alias (inode, dentry); }read_unlock (&proc_subdir_lock);
@@ -429,6 +429,8 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,INIT_LIST_HEAD (&ent->pde_openers);proc_set_user (ent, (*parent)->uid, (*parent)->gid); + ent->proc_dops = &proc_misc_dentry_ops; + out:return ent; }
fs/proc/internal.h +1 -0
@@ -44,6 +44,7 @@ struct proc_dir_entry {struct completion *pde_unload_completion;const struct inode_operations *proc_iops;const struct file_operations *proc_fops; +const struct dentry_operations *proc_dops;union {const struct seq_operations *seq_ops;int (*single_show)(struct seq_file *,void *);
fs/proc/proc_net.c +20 -0
@@ -38,6 +38,22 @@ static struct net *get_proc_net(const struct inode *inode)return maybe_get_net (PDE_NET (PDE (inode))); } +static int proc_net_d_revalidate (struct dentry *dentry,unsigned int flags) +{ +return 0 ; +} + +static const struct dentry_operations proc_net_dentry_ops = { + .d_revalidate = proc_net_d_revalidate, + .d_delete = always_delete_dentry, +}; + +static void pde_force_lookup (struct proc_dir_entry *pde) +{ +/* /proc/net/ entries can be changed under us by setns(CLONE_NEWNET) */ + pde->proc_dops = &proc_net_dentry_ops; +} +static int seq_open_net (struct inode *inode,struct file *file) {unsigned int state_size =PDE (inode)->state_size;
@@ -90,6 +106,7 @@ struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode, p =proc_create_reg (name, mode, &parent, data);if (!p)return NULL ; +pde_force_lookup (p); p->proc_fops = &proc_net_seq_fops; p->seq_ops = ops; p->state_size = state_size;
@@ -133,6 +150,7 @@ struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode p =proc_create_reg (name, mode, &parent, data);if (!p)return NULL ; +pde_force_lookup (p); p->proc_fops = &proc_net_seq_fops; p->seq_ops = ops; p->state_size = state_size;
@@ -181,6 +199,7 @@ struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode, p =proc_create_reg (name, mode, &parent, data);if (!p)return NULL ; +pde_force_lookup (p); p->proc_fops = &proc_net_single_fops; p->single_show = show;return proc_register (parent, p);
@@ -223,6 +242,7 @@ struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mo p =proc_create_reg (name, mode, &parent, data);if (!p)return NULL ; +pde_force_lookup (p); p->proc_fops = &proc_net_single_fops; p->single_show = show; p->write = write;
tools/testing/selftests/proc/.gitignore +1 -0
@@ -10,4 +10,5 @@ /proc-uptime-002 /read /self +/setns-dcache /thread-self
tools/testing/selftests/proc/Makefile +1 -0
@@ -14,6 +14,7 @@ TEST_GEN_PROGS += proc-uptime-001 TEST_GEN_PROGS += proc-uptime-002 TEST_GEN_PROGS += read TEST_GEN_PROGS += self +TEST_GEN_PROGS += setns-dcache TEST_GEN_PROGS += thread-self include ../lib.mk
tools/testing/selftests/proc/setns-dcache.c new file +129 -0
129 lines not on this page · raw message
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 64/65 autofs: drop dentry reference only when it is never used
In reply to Sasha LevinFrom: Pan Bian <[email protected]>
[ Upstream commit 63ce5f552beb9bdb41546b3a26c4374758b21815 ]
autofs_expire_run() calls dput(dentry) to drop the reference count of dentry. However, dentry is read via autofs_dentry_ino(dentry) after that. This may result in a use-free-bug. The patch drops the reference count of dentry only when it is never used.
--- fs/autofs/expire.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/autofs/expire.c +2 -1
@@ -596,7 +596,6 @@ int autofs_expire_run(struct super_block *sb, pkt.len = dentry->d_name.len;memcpy (pkt.name, dentry->d_name.name, pkt.len); pkt.name[pkt.len] ='\0' ; -dput (dentry);if (copy_to_user (pkt_p, &pkt,sizeof (struct autofs_packet_expire ))) ret = -EFAULT ;
@@ -609,6 +608,8 @@ int autofs_expire_run(struct super_block *sb,complete_all (&ino->expire_complete);spin_unlock (&sbi->fs_lock); +dput (dentry); +return ret; }
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 65/65 autofs: fix error return in autofs_fill_super()
In reply to Sasha LevinFrom: Ian Kent <[email protected]>
[ Upstream commit f585b283e3f025754c45bbe7533fc6e5c4643700 ]
In autofs_fill_super() on error of get inode/make root dentry the return should be ENOMEM as this is the only failure case of the called functions.
--- fs/autofs/inode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/autofs/inode.c +3 -1
@@ -255,8 +255,10 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) } root_inode =autofs_get_inode (s,S_IFDIR |0755 ); root =d_make_root (root_inode); -if (!root) +if (!root) { + ret = -ENOMEM ; goto fail_ino; + } pipe =NULL ; root->d_fsdata = ino;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 1/65 vti4: Fix a ipip packet processing bug in 'IPCOMP' virtual tunnel
From: Su Yanjun <[email protected]>
[ Upstream commit dd9ee3444014e8f28c0eefc9fffc9ac9c5248c12 ]
Recently we run a network test over ipcomp virtual tunnel.We find that if a ipv4 packet needs fragment, then the peer can't receive it.
We deep into the code and find that when packet need fragment the smaller fragment will be encapsulated by ipip not ipcomp. So when the ipip packet goes into xfrm, it's skb->dev is not properly set. The ipv4 reassembly code always set skb'dev to the last fragment's dev. After ipv4 defrag processing, when the kernel rp_filter parameter is set, the skb will be drop by -EXDEV error.
This patch adds compatible support for the ipip process in ipcomp virtual tunnel.
--- net/ipv4/ip_vti.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
net/ipv4/ip_vti.c +50 -0
@@ -74,6 +74,33 @@ static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,return 0 ; } +static int vti_input_ipip (struct sk_buff *skb,int nexthdr,__be32 spi, +int encap_type) +{ +struct ip_tunnel *tunnel; +const struct iphdr *iph =ip_hdr (skb); +struct net *net =dev_net (skb->dev); +struct ip_tunnel_net *itn =net_generic (net, vti_net_id); + + tunnel =ip_tunnel_lookup (itn, skb->dev->ifindex,TUNNEL_NO_KEY , + iph->saddr, iph->daddr,0 ); +if (tunnel) { +if (!xfrm4_policy_check (NULL ,XFRM_POLICY_IN , skb)) + goto drop; + +XFRM_TUNNEL_SKB_CB (skb)->tunnel.ip4 = tunnel; + + skb->dev = tunnel->dev; + +return xfrm_input (skb, nexthdr, spi, encap_type); + } + +return -EINVAL ; +drop: +kfree_skb (skb); +return 0 ; +} +static int vti_rcv (struct sk_buff *skb) {XFRM_SPI_SKB_CB (skb)->family =AF_INET ;
@@ -82,6 +109,14 @@ static int vti_rcv(struct sk_buff *skb)return vti_input (skb,ip_hdr (skb)->protocol,0 ,0 ); } +static int vti_rcv_ipip (struct sk_buff *skb) +{ +XFRM_SPI_SKB_CB (skb)->family =AF_INET ; +XFRM_SPI_SKB_CB (skb)->daddroff = offsetof(struct iphdr , daddr); + +return vti_input_ipip (skb,ip_hdr (skb)->protocol,ip_hdr (skb)->saddr,0 ); +} +static int vti_rcv_cb (struct sk_buff *skb,int err) {unsigned short family;
@@ -435,6 +470,12 @@ static struct xfrm4_protocol vti_ipcomp4_protocol __read_mostly = { .priority = 100, }; +static struct xfrm_tunnel ipip_handler__read_mostly = { + .handler = vti_rcv_ipip, + .err_handler = vti4_err, + .priority =0 , +}; +static int __net_init vti_init_net (struct net *net) {int err;
@@ -603,6 +644,13 @@ static int __init vti_init(void)if (err <0 ) goto xfrm_proto_comp_failed; + msg ="ipip tunnel" ; + err =xfrm4_tunnel_register (&ipip_handler,AF_INET ); +if (err <0 ) { +pr_info ("%s: cant't register tunnel\n" ,__func__); + goto xfrm_tunnel_failed; + } + msg ="netlink interface" ; err =rtnl_link_register (&vti_link_ops);if (err <0 )
@@ -612,6 +660,8 @@ static int __init vti_init(void) rtnl_link_failed:xfrm4_protocol_deregister (&vti_ipcomp4_protocol,IPPROTO_COMP ); +xfrm_tunnel_failed: +xfrm4_tunnel_deregister (&ipip_handler,AF_INET ); xfrm_proto_comp_failed:xfrm4_protocol_deregister (&vti_ah4_protocol,IPPROTO_AH ); xfrm_proto_ah_failed:
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 5/65 netfilter: nft_compat: make lists per netns
From: Florian Westphal <[email protected]>
[ Upstream commit cf52572ebbd7189a1966c2b5fc34b97078cd1dce ]
There are two problems with nft_compat since the netlink config plane uses a per-netns mutex:
1. Concurrent add/del accesses to the same list
2. accesses to a list element after it has been free'd already.
This patch fixes the first problem.
Freeing occurs from a work queue, after transaction mutexes have been released, i.e., it still possible for a new transaction (even from same net ns) to find the to-be-deleted expression in the list.
The ->destroy functions are not allowed to have any such side effects, i.e. the list_del() in the destroy function is not allowed.
This part of the problem is solved in the next patch. I tried to make this work by serializing list access via mutex and by moving list_del() to a deactivate callback, but Taehee spotted following race on this approach:
NET #0 NET #1
Quoted 1 line
select_ops()
->init()
->select_ops()
->deactivate()
->destroy()
nft_xt_put()
kfree_rcu(xt, rcu_head);
->init() <-- use-after-free occurred.Unfortunately, we can't increment reference count in select_ops(), because we can't undo the refcount increase in case a different expression fails in the same batch.
(The destroy hook will only be called in case the expression
was initialized successfully).
--- net/netfilter/nft_compat.c | 129 +++++++++++++++++++++++++------------ 1 file changed, 89 insertions(+), 40 deletions(-)
net/netfilter/nft_compat.c +89 -40
@@ -22,6 +22,7 @@#include <linux/netfilter_bridge/ebtables.h> #include <linux/netfilter_arp/arp_tables.h> #include <net/netfilter/nf_tables.h> +#include <net/netns/generic.h> struct nft_xt {struct list_head head;
@@ -43,6 +44,20 @@ struct nft_xt_match_priv {void *info; }; +struct nft_compat_net { +struct list_head nft_target_list; +struct list_head nft_match_list; +}; + +static unsigned int nft_compat_net_id__read_mostly ; +static struct nft_expr_type nft_match_type; +static struct nft_expr_type nft_target_type; + +static struct nft_compat_net *nft_compat_pernet (struct net *net) +{ +return net_generic (net, nft_compat_net_id); +} +static bool nft_xt_put (struct nft_xt *xt) {if (refcount_dec_and_test (&xt->refcnt)) {
@@ -714,10 +729,6 @@ static const struct nfnetlink_subsystem nfnl_compat_subsys = { .cb = nfnl_nft_compat_cb, }; -static LIST_HEAD (nft_match_list); - -static struct nft_expr_type nft_match_type; -static bool nft_match_cmp (const struct xt_match *match,const char *name,u32 rev,u32 family) {
@@ -729,6 +740,7 @@ static const struct nft_expr_ops * nft_match_select_ops(const struct nft_ctx *ctx, const struct nlattr * const tb[]) { + struct nft_compat_net *cn;struct nft_xt *nft_match;struct xt_match *match;unsigned int matchsize;
@@ -745,8 +757,10 @@ nft_match_select_ops(const struct nft_ctx *ctx, rev =ntohl (nla_get_be32 (tb[NFTA_MATCH_REV ])); family = ctx->family; + cn =nft_compat_pernet (ctx->net); +/* Re-use the existing match if it's already loaded. */ -list_for_each_entry (nft_match, &nft_match_list, head) { +list_for_each_entry (nft_match, &cn->nft_match_list, head) {struct xt_match *match = nft_match->ops.data;if (nft_match_cmp (match, mt_name, rev, family))
@@ -790,7 +804,7 @@ nft_match_select_ops(const struct nft_ctx *ctx, nft_match->ops.size = matchsize; -list_add (&nft_match->head, &nft_match_list); +list_add (&nft_match->head, &cn->nft_match_list);return &nft_match->ops; err:
@@ -806,10 +820,6 @@ static struct nft_expr_type nft_match_type __read_mostly = { .owner = THIS_MODULE, }; -static LIST_HEAD (nft_target_list); - -static struct nft_expr_type nft_target_type; -static bool nft_target_cmp (const struct xt_target *tg,const char *name,u32 rev,u32 family) {
@@ -821,6 +831,7 @@ static const struct nft_expr_ops * nft_target_select_ops(const struct nft_ctx *ctx, const struct nlattr * const tb[]) { + struct nft_compat_net *cn;struct nft_xt *nft_target;struct xt_target *target;char *tg_name;
@@ -841,8 +852,9 @@ nft_target_select_ops(const struct nft_ctx *ctx, strcmp(tg_name, "standard") == 0)return ERR_PTR (-EINVAL ); + cn =nft_compat_pernet (ctx->net);/* Re-use the existing target if it's already loaded. */ -list_for_each_entry (nft_target, &nft_target_list, head) { +list_for_each_entry (nft_target, &cn->nft_target_list, head) {struct xt_target *target = nft_target->ops.data;if (!target->target)
@@ -887,7 +899,7 @@ nft_target_select_ops(const struct nft_ctx *ctx,else nft_target->ops.eval = nft_target_eval_xt; -list_add (&nft_target->head, &nft_target_list); +list_add (&nft_target->head, &cn->nft_target_list);return &nft_target->ops; err:
@@ -903,13 +915,74 @@ static struct nft_expr_type nft_target_type __read_mostly = { .owner = THIS_MODULE, }; +static int __net_init nft_compat_init_net (struct net *net) +{ +struct nft_compat_net *cn =nft_compat_pernet (net); + +INIT_LIST_HEAD (&cn->nft_target_list); +INIT_LIST_HEAD (&cn->nft_match_list); + +return 0 ; +} + +static void __net_exit nft_compat_exit_net(struct net *net) +{ +struct nft_compat_net *cn =nft_compat_pernet (net); +struct nft_xt *xt, *next; + +if (list_empty (&cn->nft_match_list) && +list_empty (&cn->nft_target_list)) +return ; + +/* If there was an error that caused nft_xt expr to not be initialized +* fully and noone else requested the same expression later, the lists +* contain 0-refcount entries that still hold module reference. +* +* Clean them here. +*/ +mutex_lock (&net->nft.commit_mutex); +list_for_each_entry_safe (xt, next, &cn->nft_target_list, head) { +struct xt_target *target = xt->ops.data; + +list_del_init (&xt->head); + +if (refcount_read (&xt->refcnt)) +continue ; +module_put (target->me); +kfree (xt); + } + +list_for_each_entry_safe (xt, next, &cn->nft_match_list, head) { +struct xt_match *match = xt->ops.data; + +list_del_init (&xt->head); + +if (refcount_read (&xt->refcnt)) +continue ; +module_put (match->me); +kfree (xt); + } +mutex_unlock (&net->nft.commit_mutex); +} + +static struct pernet_operations nft_compat_net_ops = { + .init = nft_compat_init_net, + .exit = nft_compat_exit_net, + .id = &nft_compat_net_id, + .size =sizeof (struct nft_compat_net ), +}; +static int __init nft_compat_module_init (void ) {int ret; + ret =register_pernet_subsys (&nft_compat_net_ops); +if (ret <0 ) + goto err_target; + ret =nft_register_expr (&nft_match_type);if (ret <0 ) -return ret; + goto err_pernet; ret =nft_register_expr (&nft_target_type);if (ret <0 )
@@ -922,45 +995,21 @@ static int __init nft_compat_module_init(void) }return ret; - err_target:nft_unregister_expr (&nft_target_type); err_match:nft_unregister_expr (&nft_match_type); +err_pernet: +unregister_pernet_subsys (&nft_compat_net_ops);return ret; } static void __exit nft_compat_module_exit(void) { -struct nft_xt *xt, *next; - -/* list should be empty here, it can be non-empty only in case there -* was an error that caused nft_xt expr to not be initialized fully -* and noone else requested the same expression later. -* -* In this case, the lists contain 0-refcount entries that still -* hold module reference. -*/ -list_for_each_entry_safe (xt, next, &nft_target_list, head) { -struct xt_target *target = xt->ops.data; - -if (WARN_ON_ONCE (refcount_read (&xt->refcnt))) -continue ; -module_put (target->me); -kfree (xt); - } - -list_for_each_entry_safe (xt, next, &nft_match_list, head) { -struct xt_match *match = xt->ops.data; - -if (WARN_ON_ONCE (refcount_read (&xt->refcnt))) -continue ; -module_put (match->me); -kfree (xt); - }nfnetlink_subsys_unregister (&nfnl_compat_subsys);nft_unregister_expr (&nft_target_type);nft_unregister_expr (&nft_match_type); +unregister_pernet_subsys (&nft_compat_net_ops); }MODULE_ALIAS_NFNL_SUBSYS (NFNL_SUBSYS_NFT_COMPAT );
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 3/65 xfrm: Make set-mark default behavior backward compatible
In reply to Sasha LevinFrom: Benedict Wong <[email protected]>
[ Upstream commit e2612cd496e7b465711d219ea6118893d7253f52 ]
Fixes 9b42c1f179a6, which changed the default route lookup behavior for tunnel mode SAs in the outbound direction to use the skb mark, whereas previously mark=0 was used if the output mark was unspecified. In mark-based routing schemes such as Android’s, this change in default behavior causes routing loops or lookup failures.
This patch restores the default behavior of using a 0 mark while still incorporating the skb mark if the SET_MARK (and SET_MARK_MASK) is specified.
Tested with additions to Android's kernel unit test suite:
https://android-review.googlesource.com/c/kernel/tests/+/860150
--- net/xfrm/xfrm_policy.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/xfrm/xfrm_policy.c +4 -1
@@ -1628,7 +1628,10 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,dst_copy_metrics (dst1, dst);if (xfrm[i]->props.mode !=XFRM_MODE_TRANSPORT ) { -__u32 mark =xfrm_smark_get (fl->flowi_mark, xfrm[i]); +__u32 mark =0 ; + +if (xfrm[i]->props.smark.v || xfrm[i]->props.smark.m) + mark =xfrm_smark_get (fl->flowi_mark, xfrm[i]); family = xfrm[i]->props.family; dst = xfrm_dst_lookup(xfrm[i], tos, fl->flowi_oif,
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 9/65 perf script: Fix crash when processing recorded stat data
In reply to Sasha LevinFrom: Tony Jones <[email protected]>
[ Upstream commit 8bf8c6da53c2265aea365a1de6038f118f522113 ]
While updating perf to work with Python3 and Python2 I noticed that the stat-cpi script was dumping core.
$ perf stat -e cycles,instructions record -o /tmp/perf.data /bin/false
Performance counter stats for '/bin/false':
802,148 cycles
604,622 instructions 802,148 cycles
604,622 instructions
0.001445842 seconds time elapsed$ perf script -i /tmp/perf.data -s scripts/python/stat-cpi.py
Segmentation fault (core dumped)
...
...
rblist=rblist@entry=0xb2a200 <rt_stat>,
new_entry=new_entry@entry=0x7ffcb755c310) at util/rblist.c:33
ctx=<optimized out>, type=<optimized out>, create=<optimized out>,
cpu=<optimized out>, evsel=<optimized out>) at util/stat-shadow.c:118
ctx=<optimized out>, type=<optimized out>, st=<optimized out>)
at util/stat-shadow.c:196
count=count@entry=727442, cpu=cpu@entry=0, st=0xb2a200 <rt_stat>)
at util/stat-shadow.c:239
config=config@entry=0xafeb40 <stat_config>,
counter=counter@entry=0x133c6e0) at util/stat.c:372
...
...The issue is that since 1fcd03946b52 perf_stat__update_shadow_stats now calls update_runtime_stat passing rt_stat rather than calling update_stats but perf_stat__init_shadow_stats has never been called to initialize rt_stat in the script path processing recorded stat data.
Since I can't see any reason why perf_stat__init_shadow_stats() is presently initialized like it is in builtin-script.c::perf_sample__fprint_metric() [4bd1bef8bba2f] I'm proposing it instead be initialized once in __cmd_script
Committer testing:
After applying the patch:
# perf script -i /tmp/perf.data -s tools/perf/scripts/python/stat-cpi.py
0.001970: cpu -1, thread -1 -> cpi 1.709079 (1075684/629394)
#No segfault.
--- tools/perf/builtin-script.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
tools/perf/builtin-script.c +2 -5
@@ -1589,13 +1589,8 @@ static void perf_sample__fprint_metric(struct perf_script *script, .force_header = false, };struct perf_evsel *ev2; -static bool init;u64 val; -if (!init) { -perf_stat__init_shadow_stats (); - init = true; - }if (!evsel->stats)perf_evlist__alloc_stats (script->session->evlist, false);if (evsel_script (evsel->leader)->gnum++ ==0 )
@@ -2214,6 +2209,8 @@ static int __cmd_script(struct perf_script *script)signal (SIGINT , sig_handler); +perf_stat__init_shadow_stats (); +/* override event processing functions */ if (script->show_task_events) { script->tool.comm = process_comm_event;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 13/65 riscv: fixup max_low_pfn with PFN_DOWN.
In reply to Sasha LevinFrom: Guo Ren <[email protected]>
[ Upstream commit 28198c4639b39899a728ac89aea29d2a7a72562f ]
max_low_pfn should be pfn_size not byte_size.
--- arch/riscv/kernel/setup.c | 2 +- arch/riscv/mm/init.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
arch/riscv/kernel/setup.c +1 -1
@@ -186,7 +186,7 @@ static void __init setup_bootmem(void)BUG_ON (mem_size ==0 );set_max_mapnr (PFN_DOWN (mem_size)); - max_low_pfn =memblock_end_of_DRAM (); + max_low_pfn =PFN_DOWN (memblock_end_of_DRAM ());#ifdef CONFIG_BLK_DEV_INITRD setup_initrd ();
arch/riscv/mm/init.c +2 -1
@@ -29,7 +29,8 @@ static void __init zone_sizes_init(void)unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 , };#ifdef CONFIG_ZONE_DMA32 - max_zone_pfns[ZONE_DMA32 ] =PFN_DOWN (min (4UL *SZ_1G , max_low_pfn)); + max_zone_pfns[ZONE_DMA32 ] =PFN_DOWN (min (4UL *SZ_1G , + (unsigned long )PFN_PHYS (max_low_pfn)));#endif max_zone_pfns[ZONE_NORMAL ] = max_low_pfn;
Signature · 7 lines
2.19.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Sasha Levin
maintainerPATCH 19/65 riscv: Adjust mmap base address at a third of task size
In reply to Sasha LevinFrom: Alexandre Ghiti <[email protected]>
[ Upstream commit ae662eec8a515ab550524e04c793b5ddf1aae3a1 ]
This ratio is the most used among all other architectures and make icache_hygiene libhugetlbfs test pass: this test mmap lots of hugepages whose addresses, without this patch, reach the end of the process user address space.
--- arch/riscv/include/asm/processor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/processor.h +1 -1
@@ -22,7 +22,7 @@* This decides where the kernel will search for a free chunk of vm * space during mmap's. */ -#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE >> 1) +#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3)#define STACK_TOP TASK_SIZE#define STACK_TOP_MAX STACK_TOP
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 22/65 xtensa: SMP: fix secondary CPU initialization
In reply to Sasha LevinFrom: Max Filippov <[email protected]>
[ Upstream commit 32a7726c4f4aadfabdb82440d84f88a5a2c8fe13 ]
- add missing memory barriers to the secondary CPU synchronization spin loops; add comment to the matching memory barrier in the boot_secondary and __cpu_die functions;
- use READ_ONCE/WRITE_ONCE to access cpu_start_id/cpu_start_ccount instead of reading/writing them directly;
- re-initialize cpu_running every time before starting secondary CPU to flush possible previous CPU startup results.
--- arch/xtensa/kernel/head.S | 5 ++++- arch/xtensa/kernel/smp.c | 34 +++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-)
arch/xtensa/kernel/head.S +4 -1
@@ -280,12 +280,13 @@ should_never_return: movi a2, cpu_start_ccount 1: + memw l32i a3, a2, 0 beqi a3, 0, 1b movi a3, 0 s32i a3, a2, 0 - memw 1: + memw l32i a3, a2, 0 beqi a3, 0, 1b wsr a3, ccount
@@ -321,11 +322,13 @@ ENTRY(cpu_restart) rsr a0, prid neg a2, a0 movi a3, cpu_start_id + memw s32i a2, a3, 0 #if XCHAL_DCACHE_IS_WRITEBACK dhwbi a3, 0 #endif 1: + memw l32i a2, a3, 0 dhi a3, 0 bne a2, a0, 1b
arch/xtensa/kernel/smp.c +21 -13
@@ -195,9 +195,11 @@ static int boot_secondary(unsigned int cpu, struct task_struct *ts)int i;#ifdef CONFIG_HOTPLUG_CPU - cpu_start_id = cpu; -system_flush_invalidate_dcache_range ( - (unsigned long )&cpu_start_id,sizeof (cpu_start_id)); +WRITE_ONCE (cpu_start_id, cpu); +/* Pairs with the third memw in the cpu_restart */ +mb (); +system_flush_invalidate_dcache_range ((unsigned long )&cpu_start_id, +sizeof (cpu_start_id));#endif smp_call_function_single (0 , mx_cpu_start, (void *)cpu,1 );
@@ -206,18 +208,21 @@ static int boot_secondary(unsigned int cpu, struct task_struct *ts) ccount =get_ccount ();while (!ccount); - cpu_start_ccount = ccount; +WRITE_ONCE (cpu_start_ccount, ccount); -while (time_before (jiffies, timeout)) { +do { +/* +* Pairs with the first two memws in the +* .Lboot_secondary. +*/ mb (); -if (!cpu_start_ccount) -break ; - } + ccount =READ_ONCE (cpu_start_ccount); + }while (ccount &&time_before (jiffies, timeout)); -if (cpu_start_ccount) { +if (ccount) {smp_call_function_single (0 , mx_cpu_stop, - (void *)cpu,1 ); - cpu_start_ccount =0 ; + (void *)cpu,1 ); +WRITE_ONCE (cpu_start_ccount,0 );return -EIO ; } }
@@ -237,6 +242,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)pr_debug ("%s: Calling wakeup_secondary(cpu:%d, idle:%p, sp: %08lx)\n" , __func__, cpu, idle, start_info.stack); +init_completion (&cpu_running); ret =boot_secondary (cpu, idle);if (ret ==0 ) { wait_for_completion_timeout(&cpu_running,
@@ -298,8 +304,10 @@ void __cpu_die(unsigned int cpu)unsigned long timeout = jiffies +msecs_to_jiffies (1000 );while (time_before (jiffies, timeout)) {system_invalidate_dcache_range ((unsigned long )&cpu_start_id, -sizeof (cpu_start_id)); -if (cpu_start_id == -cpu) { +sizeof (cpu_start_id)); +/* Pairs with the second memw in the cpu_restart */ +mb (); +if (READ_ONCE (cpu_start_id) == -cpu) {platform_cpu_kill (cpu);return ; }
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 23/65 xtensa: smp_lx200_defconfig: fix vectors clash
In reply to Sasha LevinFrom: Max Filippov <[email protected]>
[ Upstream commit 306b38305c0f86de7f17c5b091a95451dcc93d7d ]
Secondary CPU reset vector overlaps part of the double exception handler code, resulting in weird crashes and hangups when running user code. Move exception vectors one page up so that they don't clash with the secondary CPU reset vector.
--- arch/xtensa/configs/smp_lx200_defconfig | 1 + 1 file changed, 1 insertion(+)
arch/xtensa/configs/smp_lx200_defconfig +1 -0
@@ -33,6 +33,7 @@ CONFIG_SMP=y CONFIG_HOTPLUG_CPU=y # CONFIG_INITIALIZE_XTENSA_MMU_INSIDE_VMLINUX is not set # CONFIG_PCI is not set +CONFIG_VECTORS_OFFSET=0x00002000 CONFIG_XTENSA_PLATFORM_XTFPGA=y CONFIG_CMDLINE_BOOL=y CONFIG_CMDLINE="earlycon=uart8250,mmio32native,0xfd050020,115200n8 console=ttyS0,115200n8 ip=dhcp root=/dev/nfs rw debug memmap=96M@0"
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 28/65 net: altera_tse: fix msgdma_tx_completion on non-zero fill_level case
In reply to Sasha LevinFrom: Tomonori Sakita <[email protected]>
[ Upstream commit 6571ebce112a21ec9be68ef2f53b96fcd41fd81b ]
If fill_level was not zero and status was not BUSY, result of "tx_prod - tx_cons - inuse" might be zero. Subtracting 1 unconditionally results invalid negative return value on this case.
Make sure not to return an negative value.
--- drivers/net/ethernet/altera/altera_msgdma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/altera/altera_msgdma.c +2 -1
@@ -145,7 +145,8 @@ u32 msgdma_tx_completions(struct altera_tse_private *priv) &0xffff ;if (inuse) {/* Tx FIFO is not empty */ - ready = priv->tx_prod - priv->tx_cons - inuse -1 ; + ready =max_t (int, + priv->tx_prod - priv->tx_cons - inuse -1 ,0 ); }else {/* Check for buffered last packet */ status =csrrd32 (priv->tx_dma_csr,msgdma_csroffs (status));
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 30/65 net: hns: Restart autoneg need return failed when autoneg off
In reply to Sasha LevinFrom: Yonglong Liu <[email protected]>
[ Upstream commit ed29ca8b9592562559c64d027fb5eb126e463e2c ]
The hns driver of earlier devices, when autoneg off, restart autoneg will return -EINVAL, so make the hns driver for the latest devices do the same.
--- drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +9 -7
@@ -1157,16 +1157,18 @@ static int hns_get_regs_len(struct net_device *net_dev)*/ static int hns_nic_nway_reset (struct net_device *netdev) { -int ret =0 ;struct phy_device *phy = netdev->phydev; -if (netif_running (netdev)) { -/* if autoneg is disabled, don't restart auto-negotiation */ -if (phy && phy->autoneg ==AUTONEG_ENABLE ) - ret =genphy_restart_aneg (phy); - } +if (!netif_running (netdev)) +return 0 ; -return ret; +if (!phy) +return -EOPNOTSUPP ; + +if (phy->autoneg !=AUTONEG_ENABLE ) +return -EINVAL ; + +return genphy_restart_aneg (phy); } static u32
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 33/65 netfilter: ebtables: compat: un-break 32bit setsockopt when no rules are present
In reply to Sasha LevinFrom: Florian Westphal <[email protected]>
[ Upstream commit 2035f3ff8eaa29cfb5c8e2160b0f6e85eeb21a95 ]
Unlike ip(6)tables ebtables only counts user-defined chains.
The effect is that a 32bit ebtables binary on a 64bit kernel can do 'ebtables -N FOO' only after adding at least one rule, else the request fails with -EINVAL.
This is a similar fix as done in3f1e53abff84 ("netfilter: ebtables: don't attempt to allocate 0-sized compat array").
--- net/bridge/netfilter/ebtables.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/bridge/netfilter/ebtables.c +6 -3
@@ -2293,9 +2293,12 @@ static int compat_do_replace(struct net *net, void __user *user,xt_compat_lock (NFPROTO_BRIDGE ); - ret =xt_compat_init_offsets (NFPROTO_BRIDGE , tmp.nentries); -if (ret <0 ) - goto out_unlock; +if (tmp.nentries) { + ret =xt_compat_init_offsets (NFPROTO_BRIDGE , tmp.nentries); +if (ret <0 ) + goto out_unlock; + } + ret =compat_copy_entries (entries_tmp, tmp.entries_size, &state);if (ret <0 ) goto out_unlock;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 39/65 qed: Fix bug in tx promiscuous mode settings
In reply to Sasha LevinFrom: Manish Chopra <[email protected]>
[ Upstream commit 9e71a15d8b5bbce25c637f7f8833cd3f45b65646 ]
When running tx switched traffic between VNICs created via a bridge(to which VFs are added), adapter drops the unicast packets in tx flow due to VNIC's ucast mac being unknown to it. But VF interfaces being in promiscuous mode should have caused adapter to accept all the unknown ucast packets. Later, it was found that driver doesn't really configure tx promiscuous mode settings to accept all unknown unicast macs.
This patch fixes tx promiscuous mode settings to accept all unknown/unmatched unicast macs and works out the scenario.
--- drivers/net/ethernet/qlogic/qed/qed_l2.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ethernet/qlogic/qed/qed_l2.c +6 -1
@@ -609,6 +609,10 @@ qed_sp_update_accept_mode(struct qed_hwfn *p_hwfn, (!!(accept_filter &QED_ACCEPT_MCAST_MATCHED ) && !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED))); +SET_FIELD (state,ETH_VPORT_TX_MODE_UCAST_ACCEPT_ALL , + (!!(accept_filter &QED_ACCEPT_UCAST_MATCHED ) && + !!(accept_filter &QED_ACCEPT_UCAST_UNMATCHED ))); +SET_FIELD (state,ETH_VPORT_TX_MODE_BCAST_ACCEPT_ALL , !!(accept_filter &QED_ACCEPT_BCAST ));
@@ -2688,7 +2692,8 @@ static int qed_configure_filter_rx_mode(struct qed_dev *cdev,if (type ==QED_FILTER_RX_MODE_TYPE_PROMISC ) { accept_flags.rx_accept_filter |=QED_ACCEPT_UCAST_UNMATCHED |QED_ACCEPT_MCAST_UNMATCHED ; - accept_flags.tx_accept_filter |=QED_ACCEPT_MCAST_UNMATCHED ; + accept_flags.tx_accept_filter |=QED_ACCEPT_UCAST_UNMATCHED | +QED_ACCEPT_MCAST_UNMATCHED ; }else if (type ==QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC ) { accept_flags.rx_accept_filter |=QED_ACCEPT_MCAST_UNMATCHED ; accept_flags.tx_accept_filter |=QED_ACCEPT_MCAST_UNMATCHED ;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 38/65 nfs: Fix NULL pointer dereference of dev_name
In reply to Sasha LevinFrom: Yao Liu <[email protected]>
[ Upstream commit 80ff00172407e0aad4b10b94ef0816fc3e7813cb ]
There is a NULL pointer dereference of dev_name in nfs_parse_devname()
The oops looks something like:
BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 ... RIP: 0010:nfs_fs_mount+0x3b6/0xc20 [nfs] ... Call Trace: ? ida_alloc_range+0x34b/0x3d0 ? nfs_clone_super+0x80/0x80 [nfs] ? nfs_free_parsed_mount_data+0x60/0x60 [nfs] mount_fs+0x52/0x170 ? __init_waitqueue_head+0x3b/0x50 vfs_kern_mount+0x6b/0x170 do_mount+0x216/0xdc0 ksys_mount+0x83/0xd0 __x64_sys_mount+0x25/0x30 do_syscall_64+0x65/0x220 entry_SYSCALL_64_after_hwframe+0x49/0xbe
Fix this by adding a NULL check on dev_name
--- fs/nfs/super.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/nfs/super.c +5 -0
@@ -1906,6 +1906,11 @@ static int nfs_parse_devname(const char *dev_name,size_t len;char *end; +if (unlikely (!dev_name || !*dev_name)) { +dfprintk (MOUNT ,"NFS: device name not specified\n" ); +return -EINVAL ; + } +/* Is the host name protected with square brakcets? */ if (*dev_name =='[' ) { end =strchr (++dev_name,']' );
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 51/65 x86/boot/compressed/64: Set EFER.LME=1 in 32-bit trampoline before returning to long mode
In reply to Sasha LevinFrom: Wei Huang <[email protected]>
[ Upstream commit b677dfae5aa197afc5191755a76a8727ffca538a ]
In some old AMD KVM implementation, guest's EFER.LME bit is cleared by KVM when the hypervsior detects that the guest sets CR0.PG to 0. This causes the guest OS to reboot when it tries to return from 32-bit trampoline code because the CPU is in incorrect state: CR4.PAE=1, CR0.PG=1, CS.L=1, but EFER.LME=0. As a precaution, set EFER.LME=1 as part of long mode activation procedure. This extra step won't cause any harm when Linux is booted on a bare-metal machine.
--- arch/x86/boot/compressed/head_64.S | 8 ++++++++ arch/x86/boot/compressed/pgtable.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/head_64.S +8 -0
@@ -600,6 +600,14 @@ ENTRY(trampoline_32bit_src) leal TRAMPOLINE_32BIT_PGTABLE_OFFSET(%ecx), %eax movl %eax, %cr3 3: + /* Set EFER.LME=1 as a precaution in case hypervsior pulls the rug */ + pushl %ecx + movl $MSR_EFER, %ecx + rdmsr + btsl $_EFER_LME, %eax + wrmsr + popl %ecx + /* Enable PAE and LA57 (if required) paging modes */ movl $X86_CR4_PAE, %eax cmpl $0, %edx
arch/x86/boot/compressed/pgtable.h +1 -1
@@ -6,7 +6,7 @@#define TRAMPOLINE_32BIT_PGTABLE_OFFSET 0#define TRAMPOLINE_32BIT_CODE_OFFSET PAGE_SIZE -#define TRAMPOLINE_32BIT_CODE_SIZE 0x60 +#define TRAMPOLINE_32BIT_CODE_SIZE 0x70#define TRAMPOLINE_32BIT_STACK_END TRAMPOLINE_32BIT_SIZE
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 53/65 blk-mq: fix a hung issue when fsync
In reply to Sasha LevinFrom: Jianchao Wang <[email protected]>
[ Upstream commit 85bd6e61f34dffa8ec2dc75ff3c02ee7b2f1cbce ]
Florian reported a io hung issue when fsync(). It should be triggered by following race condition.
data + post flush a flush
blk_flush_complete_seq
case REQ_FSEQ_DATA
blk_flush_queue_rq
issued to driver blk_mq_dispatch_rq_list
try to issue a flush req failed due to NON-NCQ command .queue_rq return BLK_STS_DEV_RESOURCE
request completion
req->end_io // doesn't check RESTART mq_flush_data_end_io
case REQ_FSEQ_POSTFLUSH
blk_kick_flush
do nothing because previous flush
has not been completed
blk_mq_run_hw_queue
insert rq to hctx->dispatch due to RESTART is still set, do nothing
To fix this, replace the blk_mq_run_hw_queue in mq_flush_data_end_io with blk_mq_sched_restart to check and clear the RESTART flag.
--- block/blk-flush.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-flush.c +1 -1
@@ -424,7 +424,7 @@ static void mq_flush_data_end_io(struct request *rq, blk_status_t error)blk_flush_complete_seq (rq, fq,REQ_FSEQ_DATA , error);spin_unlock_irqrestore (&fq->mq_flush_lock, flags); -blk_mq_run_hw_queue (hctx, true); +blk_mq_sched_restart (hctx); }/**
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 55/65 arm64: kprobe: Always blacklist the KVM world-switch code
In reply to Sasha LevinFrom: James Morse <[email protected]>
[ Upstream commit f2b3d8566d81deaca31f4e3163def0bea7746e11 ]
On systems with VHE the kernel and KVM's world-switch code run at the same exception level. Code that is only used on a VHE system does not need to be annotated as __hyp_text as it can reside anywhere in the
kernel text.
__hyp_text was also used to prevent kprobes from patching breakpoint instructions into this region, as this code runs at a different exception level. While this is no longer true with VHE, KVM still switches VBAR_EL1, meaning a kprobe's breakpoint executed in the world-switch code will cause a hyp-panic.
Move the __hyp_text check in the kprobes blacklist so it applies on VHE systems too, to cover the common code and guest enter/exit assembly.
--- arch/arm64/kernel/probes/kprobes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm64/kernel/probes/kprobes.c +3 -3
@@ -478,13 +478,13 @@ bool arch_within_kprobe_blacklist(unsigned long addr) addr < (unsigned long)__entry_text_end) || (addr >= (unsigned long )__idmap_text_start && addr < (unsigned long )__idmap_text_end) || + (addr >= (unsigned long )__hyp_text_start && + addr < (unsigned long )__hyp_text_end) || !!search_exception_tables(addr)) return true;if (!is_kernel_in_hyp_mode ()) { -if ((addr >= (unsigned long )__hyp_text_start && - addr < (unsigned long )__hyp_text_end) || - (addr >= (unsigned long )__hyp_idmap_text_start && +if ((addr >= (unsigned long )__hyp_idmap_text_start && addr < (unsigned long )__hyp_idmap_text_end))return true; }
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 56/65 apparmor: Fix aa_label_build() error handling for failed merges
In reply to Sasha LevinFrom: John Johansen <[email protected]>
[ Upstream commit d6d478aee003e19ef90321176552a8ad2929a47f ]
aa_label_merge() can return NULL for memory allocations failures make sure to handle and set the correct error in this case.
--- security/apparmor/domain.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
security/apparmor/domain.c +4 -1
@@ -1444,7 +1444,10 @@ int aa_change_profile(const char *fqname, int flags) new =aa_label_merge (label, target,GFP_KERNEL );if (IS_ERR_OR_NULL (new)) { info ="failed to build target label" ; - error =PTR_ERR (new); +if (!new) + error = -ENOMEM ; +else + error =PTR_ERR (new); new =NULL ; perms.allow =0 ; goto audit;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 59/65 x86_64: increase stack size for KASAN_EXTRA
In reply to Sasha LevinFrom: Qian Cai <[email protected]>
[ Upstream commit a8e911d13540487942d53137c156bd7707f66e5d ]
If the kernel is configured with KASAN_EXTRA, the stack size is increasted significantly because this option sets "-fstack-reuse" to "none" in GCC [1]. As a result, it triggers stack overrun quite often with 32k stack size compiled using GCC 8. For example, this reproducer
https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/madvise/madvise06.c
triggers a "corrupted stack end detected inside scheduler" very reliably with CONFIG_SCHED_STACK_END_CHECK enabled.
There are just too many functions that could have a large stack with KASAN_EXTRA due to large local variables that have been called over and over again without being able to reuse the stacks. Some noticiable ones are
size
7648 shrink_page_list
3584 xfs_rmap_convert
3312 migrate_page_move_mapping
3312 dev_ethtool
3200 migrate_misplaced_transhuge_page
3168 copy_process
There are other 49 functions are over 2k in size while compiling kernel with "-Wframe-larger-than=" even with a related minimal config on this machine. Hence, it is too much work to change Makefiles for each object to compile without "-fsanitize-address-use-after-scope" individually.
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715#c23
Although there is a patch in GCC 9 to help the situation, GCC 9 probably won't be released in a few months and then it probably take another 6-month to 1-year for all major distros to include it as a default. Hence, the stack usage with KASAN_EXTRA can be revisited again in 2020 when GCC 9 is everywhere. Until then, this patch will help users avoid stack overrun.
This has already been fixed for arm64 for the same reason via 6e8830674ea ("arm64: kasan: Increase stack size for KASAN_EXTRA").
--- arch/x86/include/asm/page_64_types.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/include/asm/page_64_types.h +4 -0
@@ -7,7 +7,11 @@#endif #ifdef CONFIG_KASAN +#ifdef CONFIG_KASAN_EXTRA +#define KASAN_STACK_ORDER 2 +#else #define KASAN_STACK_ORDER 1 +#endif #else #define KASAN_STACK_ORDER 0#endif
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 60/65 mm, memory_hotplug: is_mem_section_removable do not pass the end of a zone
In reply to Sasha LevinFrom: Michal Hocko <[email protected]>
[ Upstream commit efad4e475c312456edb3c789d0996d12ed744c13 ]
Patch series "mm, memory_hotplug: fix uninitialized pages fallouts", v2.
Mikhail Zaslonko has posted fixes for the two bugs quite some time ago [1]. I have pushed back on those fixes because I believed that it is much better to plug the problem at the initialization time rather than play whack-a-mole all over the hotplug code and find all the places which expect the full memory section to be initialized.
We have ended up with commit 2830bf6f05fb ("mm, memory_hotplug:
initialize struct pages for the full memory section") merged and cause a regression [2][3]. The reason is that there might be memory layouts when two NUMA nodes share the same memory section so the merged fix is simply incorrect.
In order to plug this hole we really have to be zone range aware in those handlers. I have split up the original patch into two. One is unchanged (patch 2) and I took a different approach for `removable' crash.
[1] http://lkml.kernel.org/r/[email protected]
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1666948
[3] http://lkml.kernel.org/r/[email protected]
This patch (of 2):
Mikhail has reported the following VM_BUG_ON triggered when reading sysfs removable state of a memory block:
page:000003d08300c000 is uninitialized and poisoned
page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) Call Trace: is_mem_section_removable+0xb4/0x190 show_mem_removable+0x9a/0xd8 dev_attr_show+0x34/0x70 sysfs_kf_seq_show+0xc8/0x148 seq_read+0x204/0x480 __vfs_read+0x32/0x178 vfs_read+0x82/0x138 ksys_read+0x5a/0xb0 system_call+0xdc/0x2d8 Last Breaking-Event-Address: is_mem_section_removable+0xb4/0x190 Kernel panic - not syncing: Fatal exception: panic_on_oops
The reason is that the memory block spans the zone boundary and we are stumbling over an unitialized struct page. Fix this by enforcing zone range in is_mem_section_removable so that we never run away from a zone.
--- mm/memory_hotplug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/memory_hotplug.c +2 -1
@@ -1258,7 +1258,8 @@ static bool is_pageblock_removable_nolock(struct page *page)bool is_mem_section_removable (unsigned long start_pfn,unsigned long nr_pages) {struct page *page =pfn_to_page (start_pfn); -struct page *end_page = page + nr_pages; +unsigned long end_pfn =min (start_pfn + nr_pages,zone_end_pfn (page_zone (page))); +struct page *end_page =pfn_to_page (end_pfn);/* Check the starting page of each pageblock within the range */ for (; page < end_page; page =next_active_pageblock (page)) {
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 61/65 mm, memory_hotplug: test_pages_in_a_zone do not pass the end of zone
In reply to Sasha LevinFrom: Mikhail Zaslonko <[email protected]>
[ Upstream commit 24feb47c5fa5b825efb0151f28906dfdad027e61 ]
If memory end is not aligned with the sparse memory section boundary, the mapping of such a section is only partly initialized. This may lead to VM_BUG_ON due to uninitialized struct pages access from test_pages_in_a_zone() function triggered by memory_hotplug sysfs handlers.
Here are the the panic examples:
CONFIG_DEBUG_VM_PGFLAGS=y
kernel parameter mem=2050M
--------------------------
page:000003d082008000 is uninitialized and poisoned
page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) Call Trace: test_pages_in_a_zone+0xde/0x160 show_valid_zones+0x5c/0x190 dev_attr_show+0x34/0x70 sysfs_kf_seq_show+0xc8/0x148 seq_read+0x204/0x480 __vfs_read+0x32/0x178 vfs_read+0x82/0x138 ksys_read+0x5a/0xb0 system_call+0xdc/0x2d8 Last Breaking-Event-Address: test_pages_in_a_zone+0xde/0x160 Kernel panic - not syncing: Fatal exception: panic_on_oops
Fix this by checking whether the pfn to check is within the zone.
[[email protected]: separated this change from
http://lkml.kernel.org/r/[email protected]]
--- mm/memory_hotplug.c | 3 +++ 1 file changed, 3 insertions(+)
mm/memory_hotplug.c +3 -0
@@ -1299,6 +1299,9 @@ int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn, i++;if (i ==MAX_ORDER_NR_PAGES || pfn + i >= end_pfn)continue ; +/* Check if we got outside of the zone */ +if (zone && !zone_spans_pfn (zone, pfn + i)) +return 0 ; page =pfn_to_page (pfn + i);if (zone &&page_zone (page) != zone)return 0 ;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 62/65 lib/test_kmod.c: potential double free in error handling
In reply to Sasha LevinFrom: Dan Carpenter <[email protected]>
[ Upstream commit db7ddeab3ce5d64c9696e70d61f45ea9909cd196 ]
There is a copy and paste bug so we set "config->test_driver" to NULL twice instead of setting "config->test_fs". Smatch complains that it leads to a double free:
lib/test_kmod.c:840 __kmod_config_init() warn: 'config->test_fs' double freed
--- lib/test_kmod.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/test_kmod.c +1 -1
@@ -632,7 +632,7 @@ static void __kmod_config_free(struct test_config *config) config->test_driver =NULL ;kfree_const (config->test_fs); - config->test_driver =NULL ; + config->test_fs =NULL ; }static void kmod_config_free (struct kmod_test_device *test_dev)
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 63/65 fs/drop_caches.c: avoid softlockups in drop_pagecache_sb()
In reply to Sasha LevinFrom: Jan Kara <[email protected]>
[ Upstream commit c27d82f52f75fc9d8d9d40d120d2a96fdeeada5e ]
When superblock has lots of inodes without any pagecache (like is the case for /proc), drop_pagecache_sb() will iterate through all of them without dropping sb->s_inode_list_lock which can lead to softlockups (one of our customers hit this).
Fix the problem by going to the slow path and doing cond_resched() in case the process needs rescheduling.
--- fs/drop_caches.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/drop_caches.c +7 -1
@@ -21,8 +21,13 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)spin_lock (&sb->s_inode_list_lock);list_for_each_entry (inode, &sb->s_inodes, i_sb_list) {spin_lock (&inode->i_lock); +/* +* We must skip inodes in unusual state. We may also skip +* inodes without pages but we deliberately won't in case +* we need to reschedule to avoid softlockups. +*/ if ((inode->i_state & (I_FREEING |I_WILL_FREE |I_NEW )) || - (inode->i_mapping->nrpages ==0 )) { + (inode->i_mapping->nrpages ==0 && !need_resched ())) {spin_unlock (&inode->i_lock);continue ; }
@@ -30,6 +35,7 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)spin_unlock (&inode->i_lock);spin_unlock (&sb->s_inode_list_lock); +cond_resched ();invalidate_mapping_pages (inode->i_mapping,0 ,-1 );iput (toput_inode); toput_inode = inode;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 54/65 x86/microcode/amd: Don't falsely trick the late loading mechanism
In reply to Sasha LevinFrom: Thomas Lendacky <[email protected]>
[ Upstream commit 912139cfbfa6a2bc1da052314d2c29338dae1f6a ]
The load_microcode_amd() function searches for microcode patches and attempts to apply a microcode patch if it is of different level than the currently installed level.
While the processor won't actually load a level that is less than what is already installed, the logic wrongly returns UCODE_NEW thus signaling to its caller reload_store() that a late loading should be attempted.
If the file-system contains an older microcode revision than what is currently running, such a late microcode reload can result in these misleading messages:
x86/CPU: CPU features have changed after loading microcode, but might not take effect. x86/CPU: Please consider either early loading through initrd/built-in or a potential BIOS update.
These messages were issued on a system where SME/SEV are not enabled by the BIOS (MSR C001_0010[23] = 0b) because during boot, early_detect_mem_encrypt() is called and cleared the SME and SEV features in this case.
However, after the wrong late load attempt, get_cpu_cap() is called and reloads the SME and SEV feature bits, resulting in the messages.
Update the microcode level check to not attempt microcode loading if the current level is greater than(!) and not only equal to the current patch level.
[ bp: massage commit message. ]
--- arch/x86/kernel/cpu/microcode/amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -707,7 +707,7 @@ load_microcode_amd(bool save, u8 family, const u8 *data, size_t size)if (!p) {return ret; }else { -if (boot_cpu_data.microcode == p->patch_id) +if (boot_cpu_data.microcode >= p->patch_id)return ret; ret =UCODE_NEW ;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 52/65 cifs: fix computation for MAX_SMB2_HDR_SIZE
In reply to Sasha LevinFrom: Ronnie Sahlberg <[email protected]>
[ Upstream commit 58d15ed1203f4d858c339ea4d7dafa94bd2a56d3 ]
The size of the fixed part of the create response is 88 bytes not 56.
--- fs/cifs/smb2pdu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/cifs/smb2pdu.h +2 -2
@@ -84,8 +84,8 @@#define NUMBER_OF_SMB2_COMMANDS 0x0013 -/* 4 len + 52 transform hdr + 64 hdr + 56 create rsp */ -#define MAX_SMB2_HDR_SIZE 0x00b0 +/* 52 transform hdr + 64 hdr + 88 create rsp */ +#define MAX_SMB2_HDR_SIZE 204#define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)#define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 50/65 net: macb: Apply RXUBR workaround only to versions with errata
In reply to Sasha LevinFrom: Harini Katakam <[email protected]>
[ Upstream commit e501070e4db0b67a4c17a5557d1e9d098f3db310 ]
The interrupt handler contains a workaround for RX hang applicable to Zynq and AT91RM9200 only. Subsequent versions do not need this workaround. This workaround unnecessarily resets RX whenever RX used bit read is observed, which can be often under heavy traffic. There is no other action performed on RX UBR interrupt. Hence introduce a CAPS mask; enable this interrupt and workaround only on affected versions.
--- drivers/net/ethernet/cadence/macb.h | 3 +++ drivers/net/ethernet/cadence/macb_main.c | 28 ++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-)
drivers/net/ethernet/cadence/macb.h +3 -0
@@ -643,6 +643,7 @@#define MACB_CAPS_JUMBO 0x00000020#define MACB_CAPS_GEM_HAS_PTP 0x00000040#define MACB_CAPS_BD_RD_PREFETCH 0x00000080 +#define MACB_CAPS_NEEDS_RSTONUBR 0x00000100#define MACB_CAPS_FIFO_MODE 0x10000000#define MACB_CAPS_GIGABIT_MODE_AVAILABLE 0x20000000#define MACB_CAPS_SG_DISABLED 0x40000000
@@ -1214,6 +1215,8 @@ struct macb {int rx_bd_rd_prefetch;int tx_bd_rd_prefetch; + +u32 rx_intr_mask; };#ifdef CONFIG_MACB_USE_HWSTAMP
drivers/net/ethernet/cadence/macb_main.c +17 -11
@@ -56,8 +56,7 @@/* level of occupied TX descriptors under which we wake up TX process */ #define MACB_TX_WAKEUP_THRESH (bp) (3 * (bp)->tx_ring_size / 4) -#define MACB_RX_INT_FLAGS (MACB_BIT(RCOMP) | MACB_BIT(RXUBR) \ - | MACB_BIT(ISR_ROVR)) +#define MACB_RX_INT_FLAGS (MACB_BIT(RCOMP) | MACB_BIT(ISR_ROVR))#define MACB_TX_ERR_FLAGS (MACB_BIT(ISR_TUND) \ | MACB_BIT(ISR_RLE) \ | MACB_BIT(TXERR))
@@ -1271,7 +1270,7 @@ static int macb_poll(struct napi_struct *napi, int budget)queue_writel (queue,ISR ,MACB_BIT (RCOMP ));napi_reschedule (napi); }else { -queue_writel (queue,IER ,MACB_RX_INT_FLAGS ); +queue_writel (queue,IER , bp->rx_intr_mask); } }
@@ -1289,7 +1288,7 @@ static void macb_hresp_error_task(unsigned long data)u32 ctrl;for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue) { -queue_writel (queue,IDR ,MACB_RX_INT_FLAGS | +queue_writel (queue,IDR , bp->rx_intr_mask |MACB_TX_INT_FLAGS |MACB_BIT (HRESP )); }
@@ -1319,7 +1318,7 @@ static void macb_hresp_error_task(unsigned long data)/* Enable interrupts */ queue_writel (queue,IER , -MACB_RX_INT_FLAGS | + bp->rx_intr_mask |MACB_TX_INT_FLAGS |MACB_BIT (HRESP )); }
@@ -1373,14 +1372,14 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id) (unsigned int )(queue - bp->queues), (unsigned long)status); -if (status &MACB_RX_INT_FLAGS ) { +if (status & bp->rx_intr_mask) {/* There's no point taking any more interrupts * until we have processed the buffers. The * scheduling call may fail if the poll routine * is already scheduled, so disable interrupts * now. */ -queue_writel (queue,IDR ,MACB_RX_INT_FLAGS ); +queue_writel (queue,IDR , bp->rx_intr_mask);if (bp->caps &MACB_CAPS_ISR_CLEAR_ON_WRITE )queue_writel (queue,ISR ,MACB_BIT (RCOMP ));
@@ -1413,8 +1412,9 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)/* There is a hardware issue under heavy load where DMA can * stop, this causes endless "used buffer descriptor read" * interrupts but it can be cleared by re-enabling RX. See -* the at91 manual, section 41.3.1 or the Zynq manual -* section 16.7.4 for details. +* the at91rm9200 manual, section 41.3.1 or the Zynq manual +* section 16.7.4 for details. RXUBR is only enabled for +* these two versions. */ if (status &MACB_BIT (RXUBR )) { ctrl =macb_readl (bp,NCR );
@@ -2264,7 +2264,7 @@ static void macb_init_hw(struct macb *bp)/* Enable interrupts */ queue_writel (queue,IER , -MACB_RX_INT_FLAGS | + bp->rx_intr_mask |MACB_TX_INT_FLAGS |MACB_BIT (HRESP )); }
@@ -3912,6 +3912,7 @@ static const struct macb_config sama5d4_config = { };static const struct macb_config emac_config = { + .caps =MACB_CAPS_NEEDS_RSTONUBR , .clk_init = at91ether_clk_init, .init = at91ether_init, };
@@ -3933,7 +3934,8 @@ static const struct macb_config zynqmp_config = { };static const struct macb_config zynq_config = { - .caps =MACB_CAPS_GIGABIT_MODE_AVAILABLE |MACB_CAPS_NO_GIGABIT_HALF , + .caps =MACB_CAPS_GIGABIT_MODE_AVAILABLE |MACB_CAPS_NO_GIGABIT_HALF | +MACB_CAPS_NEEDS_RSTONUBR , .dma_burst_length =16 , .clk_init = macb_clk_init, .init = macb_init,
@@ -4088,6 +4090,10 @@ static int macb_probe(struct platform_device *pdev)macb_dma_desc_get_size (bp); } + bp->rx_intr_mask =MACB_RX_INT_FLAGS ; +if (bp->caps &MACB_CAPS_NEEDS_RSTONUBR ) + bp->rx_intr_mask |=MACB_BIT (RXUBR ); + mac =of_get_mac_address (np);if (mac) {ether_addr_copy (bp->dev->dev_addr, mac);
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 43/65 qed: Fix stack out of bounds bug
In reply to Sasha LevinFrom: Manish Chopra <[email protected]>
[ Upstream commit ffb057f98928aa099b08e419bbe5afc26ec9f448 ]
KASAN reported following bug in qed_init_qm_get_idx_from_flags due to inappropriate casting of "pq_flags". Fix the type of "pq_flags".
[ 196.624707] BUG: KASAN: stack-out-of-bounds in qed_init_qm_get_idx_from_flags+0x1a4/0x1b8 [qed] [ 196.624712] Read of size 8 at addr ffff809b00bc7360 by task kworker/0:9/1712 [ 196.624714] [ 196.624720] CPU: 0 PID: 1712 Comm: kworker/0:9 Not tainted 4.18.0-60.el8.aarch64+debug #1 [ 196.624723] Hardware name: To be filled by O.E.M. Saber/Saber, BIOS 0ACKL024 09/26/2018 [ 196.624733] Workqueue: events work_for_cpu_fn [ 196.624738] Call trace: [ 196.624742] dump_backtrace+0x0/0x2f8 [ 196.624745] show_stack+0x24/0x30 [ 196.624749] dump_stack+0xe0/0x11c [ 196.624755] print_address_description+0x68/0x260 [ 196.624759] kasan_report+0x178/0x340 [ 196.624762] __asan_report_load_n_noabort+0x38/0x48 [ 196.624786] qed_init_qm_get_idx_from_flags+0x1a4/0x1b8 [qed] [ 196.624808] qed_init_qm_info+0xec0/0x2200 [qed] [ 196.624830] qed_resc_alloc+0x284/0x7e8 [qed] [ 196.624853] qed_slowpath_start+0x6cc/0x1ae8 [qed] [ 196.624864] __qede_probe.isra.10+0x1cc/0x12c0 [qede] [ 196.624874] qede_probe+0x78/0xf0 [qede] [ 196.624879] local_pci_probe+0xc4/0x180 [ 196.624882] work_for_cpu_fn+0x54/0x98 [ 196.624885] process_one_work+0x758/0x1900 [ 196.624888] worker_thread+0x4e0/0xd18 [ 196.624892] kthread+0x2c8/0x350 [ 196.624897] ret_from_fork+0x10/0x18 [ 196.624899] [ 196.624902] Allocated by task 2: [ 196.624906] kasan_kmalloc.part.1+0x40/0x108 [ 196.624909] kasan_kmalloc+0xb4/0xc8 [ 196.624913] kasan_slab_alloc+0x14/0x20 [ 196.624916] kmem_cache_alloc_node+0x1dc/0x480 [ 196.624921] copy_process.isra.1.part.2+0x1d8/0x4a98 [ 196.624924] _do_fork+0x150/0xfa0 [ 196.624926] kernel_thread+0x48/0x58 [ 196.624930] kthreadd+0x3a4/0x5a0 [ 196.624932] ret_from_fork+0x10/0x18 [ 196.624934] [ 196.624937] Freed by task 0: [ 196.624938] (stack is not available) [ 196.624940] [ 196.624943] The buggy address belongs to the object at ffff809b00bc0000 [ 196.624943] which belongs to the cache thread_stack of size 32768 [ 196.624946] The buggy address is located 29536 bytes inside of [ 196.624946] 32768-byte region [ffff809b00bc0000, ffff809b00bc8000) [ 196.624948] The buggy address belongs to the page: [ 196.624952] page:ffff7fe026c02e00 count:1 mapcount:0 mapping:ffff809b4001c000 index:0x0 compound_mapcount: 0 [ 196.624960] flags: 0xfffff8000008100(slab|head) [ 196.624967] raw: 0fffff8000008100 dead000000000100 dead000000000200 ffff809b4001c000 [ 196.624970] raw: 0000000000000000 0000000000080008 00000001ffffffff 0000000000000000 [ 196.624973] page dumped because: kasan: bad access detected [ 196.624974] [ 196.624976] Memory state around the buggy address: [ 196.624980] ffff809b00bc7200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 196.624983] ffff809b00bc7280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 196.624985] >ffff809b00bc7300: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 04 f2 f2 f2 [ 196.624988] ^ [ 196.624990] ffff809b00bc7380: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 196.624993] ffff809b00bc7400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 196.624995] ==================================================================
--- drivers/net/ethernet/qlogic/qed/qed_dev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/qlogic/qed/qed_dev.c +4 -4
@@ -473,19 +473,19 @@ static void qed_init_qm_pq(struct qed_hwfn *p_hwfn,/* get pq index according to PQ_FLAGS */ static u16 *qed_init_qm_get_idx_from_flags (struct qed_hwfn *p_hwfn, -u32 pq_flags) +unsigned long pq_flags) {struct qed_qm_info *qm_info = &p_hwfn->qm_info;/* Can't have multiple flags set here */ -if (bitmap_weight ((unsigned long *)&pq_flags, +if (bitmap_weight (&pq_flags,sizeof (pq_flags) *BITS_PER_BYTE ) >1 ) { -DP_ERR (p_hwfn,"requested multiple pq flags 0x%x\n" , pq_flags); +DP_ERR (p_hwfn,"requested multiple pq flags 0x%lx\n" , pq_flags); goto err; }if (!(qed_get_pq_flags (p_hwfn) & pq_flags)) { -DP_ERR (p_hwfn,"pq flag 0x%x is not set\n" , pq_flags); +DP_ERR (p_hwfn,"pq flag 0x%lx is not set\n" , pq_flags); goto err; }
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 42/65 qed: Fix system crash in ll2 xmit
In reply to Sasha LevinFrom: Manish Chopra <[email protected]>
[ Upstream commit 7c81626a3c37e4ac320b8ad785694ba498f24794 ]
Cache number of fragments in the skb locally as in case of linear skb (with zero fragments), tx completion (or freeing of skb) may happen before driver tries to get number of frgaments from the skb which could lead to stale access to an already freed skb.
--- drivers/net/ethernet/qlogic/qed/qed_ll2.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/net/ethernet/qlogic/qed/qed_ll2.c +15 -5
@@ -2426,19 +2426,24 @@ static int qed_ll2_start_xmit(struct qed_dev *cdev, struct sk_buff *skb, {struct qed_ll2_tx_pkt_info pkt;const skb_frag_t *frag; +u8 flags =0 , nr_frags;int rc = -EINVAL , i;dma_addr_t mapping;u16 vlan =0 ; -u8 flags =0 ;if (unlikely (skb->ip_summed !=CHECKSUM_NONE )) {DP_INFO (cdev,"Cannot transmit a checksummed packet\n" );return -EINVAL ; } -if (1 +skb_shinfo (skb)->nr_frags >CORE_LL2_TX_MAX_BDS_PER_PACKET ) { +/* Cache number of fragments from SKB since SKB may be freed by +* the completion routine after calling qed_ll2_prepare_tx_packet() +*/ + nr_frags =skb_shinfo (skb)->nr_frags; + +if (1 + nr_frags >CORE_LL2_TX_MAX_BDS_PER_PACKET ) {DP_ERR (cdev,"Cannot transmit a packet with %d fragments\n" , -1 +skb_shinfo (skb)->nr_frags); +1 + nr_frags);return -EINVAL ; }
@@ -2460,7 +2465,7 @@ static int qed_ll2_start_xmit(struct qed_dev *cdev, struct sk_buff *skb, }memset (&pkt,0 ,sizeof (pkt)); - pkt.num_of_bds =1 +skb_shinfo (skb)->nr_frags; + pkt.num_of_bds =1 + nr_frags; pkt.vlan = vlan; pkt.bd_flags = flags; pkt.tx_dest =QED_LL2_TX_DEST_NW ;
@@ -2471,12 +2476,17 @@ static int qed_ll2_start_xmit(struct qed_dev *cdev, struct sk_buff *skb, test_bit(QED_LL2_XMIT_FLAGS_FIP_DISCOVERY, &xmit_flags)) pkt.remove_stag = true; +/* qed_ll2_prepare_tx_packet() may actually send the packet if +* there are no fragments in the skb and subsequently the completion +* routine may run and free the SKB, so no dereferencing the SKB +* beyond this point unless skb has any fragments. +*/ rc =qed_ll2_prepare_tx_packet (&cdev->hwfns[0 ], cdev->ll2->handle, &pkt,1 );if (rc) goto err; -for (i =0 ; i <skb_shinfo (skb)->nr_frags; i++) { +for (i =0 ; i < nr_frags; i++) { frag = &skb_shinfo (skb)->frags[i]; mapping = skb_frag_dma_map(&cdev->pdev->dev, frag, 0,
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 40/65 qed: Fix LACP pdu drops for VFs
In reply to Sasha LevinFrom: Manish Chopra <[email protected]>
[ Upstream commit ff9296966e5e00b0d0d00477b2365a178f0f06a3 ]
VF is always configured to drop control frames (with reserved mac addresses) but to work LACP on the VFs, it would require LACP control frames to be forwarded or transmitted successfully.
This patch fixes this in such a way that trusted VFs (marked through ndo_set_vf_trust) would be allowed to pass the control frames such as LACP pdus.
--- drivers/net/ethernet/qlogic/qed/qed_l2.c | 5 +++++ drivers/net/ethernet/qlogic/qed/qed_l2.h | 3 +++ drivers/net/ethernet/qlogic/qed/qed_sriov.c | 10 ++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-)
drivers/net/ethernet/qlogic/qed/qed_l2.c +5 -0
@@ -748,6 +748,11 @@ int qed_sp_vport_update(struct qed_hwfn *p_hwfn,return rc; } +if (p_params->update_ctl_frame_check) { + p_cmn->ctl_frame_mac_check_en = p_params->mac_chk_en; + p_cmn->ctl_frame_ethtype_check_en = p_params->ethtype_chk_en; + } +/* Update mcast bins for VFs, PF doesn't use this functionality */ qed_sp_update_mcast_bin (p_hwfn, p_ramrod, p_params);
drivers/net/ethernet/qlogic/qed/qed_l2.h +3 -0
@@ -219,6 +219,9 @@ struct qed_sp_vport_update_params {struct qed_rss_params *rss_params;struct qed_filter_accept_flags accept_flags;struct qed_sge_tpa_params *sge_tpa_params; +u8 update_ctl_frame_check; +u8 mac_chk_en; +u8 ethtype_chk_en; }; int qed_sp_vport_update(struct qed_hwfn *p_hwfn,
drivers/net/ethernet/qlogic/qed/qed_sriov.c +8 -2
@@ -1969,7 +1969,9 @@ static void qed_iov_vf_mbx_start_vport(struct qed_hwfn *p_hwfn, params.vport_id = vf->vport_id; params.max_buffers_per_cqe = start->max_buffers_per_cqe; params.mtu = vf->mtu; - params.check_mac = true; + +/* Non trusted VFs should enable control frame filtering */ + params.check_mac = !vf->p_vf_info.is_trusted_configured; rc =qed_sp_eth_vport_start (p_hwfn, ¶ms);if (rc) {
@@ -5130,6 +5132,9 @@ static void qed_iov_handle_trust_change(struct qed_hwfn *hwfn) params.opaque_fid = vf->opaque_fid; params.vport_id = vf->vport_id; + params.update_ctl_frame_check =1 ; + params.mac_chk_en = !vf_info->is_trusted_configured; +if (vf_info->rx_accept_mode & mask) { flags->update_rx_mode_config =1 ; flags->rx_accept_filter = vf_info->rx_accept_mode;
@@ -5147,7 +5152,8 @@ static void qed_iov_handle_trust_change(struct qed_hwfn *hwfn) }if (flags->update_rx_mode_config || - flags->update_tx_mode_config) + flags->update_tx_mode_config || + params.update_ctl_frame_check)qed_sp_vport_update (hwfn, ¶ms,QED_SPQ_MODE_EBLOCK ,NULL ); }
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 41/65 qed: Fix VF probe failure while FLR
In reply to Sasha LevinFrom: Manish Chopra <[email protected]>
[ Upstream commit 327852ec64205bb651be391a069784872098a3b2 ]
VFs may hit VF-PF channel timeout while probing, as in some cases it was observed that VF FLR and VF "acquire" message transaction (i.e first message from VF to PF in VF's probe flow) could occur simultaneously which could lead VF to fail sending "acquire" message to PF as VF is marked disabled from HW perspective due to FLR, which will result into channel timeout and VF probe failure.
In such cases, try retrying VF "acquire" message so that in later attempts it could be successful to pass message to PF after the VF FLR is completed and can be probed successfully.
--- drivers/net/ethernet/qlogic/qed/qed_vf.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/net/ethernet/qlogic/qed/qed_vf.c +10 -0
@@ -261,6 +261,7 @@ static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;struct vf_pf_resc_request *p_resc; +u8 retry_cnt =VF_ACQUIRE_THRESH ;bool resources_acquired = false;struct vfpf_acquire_tlv *req;int rc =0 , attempts =0 ;
@@ -314,6 +315,15 @@ static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)/* send acquire request */ rc =qed_send_msg2pf (p_hwfn, &resp->hdr.status,sizeof (*resp)); + +/* Re-try acquire in case of vf-pf hw channel timeout */ +if (retry_cnt && rc == -EBUSY ) { +DP_VERBOSE (p_hwfn,QED_MSG_IOV , +"VF retrying to acquire due to VPC timeout\n" ); + retry_cnt--; +continue ; + } +if (rc) goto exit;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 32/65 net: stmmac: dwmac-rk: fix error handling in rk_gmac_powerup()
In reply to Sasha LevinFrom: Alexey Khoroshilov <[email protected]>
[ Upstream commit c69c29a1a0a8f68cd87e98ba4a5a79fb8ef2a58c ]
If phy_power_on() fails in rk_gmac_powerup(), clocks are left enabled.
Found by Linux Driver Verification project (linuxtesting.org).
--- drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +3 -1
@@ -1342,8 +1342,10 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv) } ret =phy_power_on (bsp_priv, true); -if (ret) +if (ret) { +gmac_clk_enable (bsp_priv, false);return ret; + }pm_runtime_enable (dev);pm_runtime_get_sync (dev);
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 34/65 netfilter: nfnetlink_osf: add missing fmatch check
In reply to Sasha LevinFrom: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 1a6a0951fc009f6d9fe8ebea2d2417d80d54097b ]
When we check the tcp options of a packet and it doesn't match the current fingerprint, the tcp packet option pointer must be restored to its initial value in order to do the proper tcp options check for the next fingerprint.
Here we can see an example.
Assumming the following fingerprint base with two lines:
S10:64:1:60:M*,S,T,N,W6: Linux:3.0::Linux 3.0
S20:64:1:60:M*,S,T,N,W7: Linux:4.19:arch:Linux 4.1
Where TCP options are the last field in the OS signature, all of them overlap except by the last one, ie. 'W6' versus 'W7'.
In case a packet for Linux 4.19 kicks in, the osf finds no matching because the TCP options pointer is updated after checking for the TCP options in the first line.
Therefore, reset pointer back to where it should be.
--- net/netfilter/nfnetlink_osf.c | 4 ++++ 1 file changed, 4 insertions(+)
net/netfilter/nfnetlink_osf.c +4 -0
@@ -71,6 +71,7 @@ static bool nf_osf_match_one(const struct sk_buff *skb,int ttl_check, struct nf_osf_hdr_ctx *ctx) { + const __u8 *optpinit = ctx->optp;unsigned int check_WSS =0 ;int fmatch =FMATCH_WRONG ;int foptsize, optnum;
@@ -160,6 +161,9 @@ static bool nf_osf_match_one(const struct sk_buff *skb, } } +if (fmatch !=FMATCH_OK ) + ctx->optp = optpinit; +return fmatch ==FMATCH_OK ; }
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 31/65 net: hns: Fix wrong read accesses via Clause 45 MDIO protocol
In reply to Sasha LevinFrom: Yonglong Liu <[email protected]>
[ Upstream commit cec8abba13e6a26729dfed41019720068eeeff2b ]
When reading phy registers via Clause 45 MDIO protocol, after write address operation, the driver use another write address operation, so can not read the right value of any phy registers. This patch fixes it.
--- drivers/net/ethernet/hisilicon/hns_mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/hisilicon/hns_mdio.c +1 -1
@@ -321,7 +321,7 @@ static int hns_mdio_read(struct mii_bus *bus, int phy_id, int regnum) }hns_mdio_cmd_write (mdio_dev, is_c45, -MDIO_C45_WRITE_ADDR , phy_id, devad); +MDIO_C45_READ , phy_id, devad); }/* Step 5: waitting for MDIO_COMMAND_REG 's mdio_start==0,*/
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 27/65 xtensa: SMP: limit number of possible CPUs by NR_CPUS
In reply to Sasha LevinFrom: Max Filippov <[email protected]>
[ Upstream commit 25384ce5f9530def39421597b1457d9462df6455 ]
This fixes the following warning at boot when the kernel is booted on a board with more CPU cores than was configured in NR_CPUS:
smp_init_cpus: Core Count = 8
smp_init_cpus: Core Id = 0
------------[ cut here ]------------
WARNING: CPU: 0 PID: 0 at include/linux/cpumask.h:121 smp_init_cpus+0x54/0x74
Modules linked in:
CPU: 0 PID: 0 Comm: swapper Not tainted 5.0.0-rc3-00015-g1459333f88a0 #124
Call Trace:
__warn$part$3+0x6a/0x7c
warn_slowpath_null+0x35/0x3c
smp_init_cpus+0x54/0x74
setup_arch+0x1c0/0x1d0
start_kernel+0x44/0x310
_startup+0x107/0x107--- arch/xtensa/kernel/smp.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/xtensa/kernel/smp.c +5 -0
@@ -96,6 +96,11 @@ void __init smp_init_cpus(void)pr_info ("%s: Core Count = %d\n" , __func__, ncpus);pr_info ("%s: Core Id = %d\n" , __func__, core_id); +if (ncpus >NR_CPUS ) { + ncpus =NR_CPUS ; +pr_info ("%s: limiting core count by %d\n" , __func__, ncpus); + } +for (i =0 ; i < ncpus; ++i)set_cpu_possible (i, true); }
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 29/65 net: hns: Fix for missing of_node_put() after of_parse_phandle()
In reply to Sasha LevinFrom: Yonglong Liu <[email protected]>
[ Upstream commit 263c6d75f9a544a3c2f8f6a26de4f4808d8f59cf ]
In hns enet driver, we use of_parse_handle() to get hold of the device node related to "ae-handle" but we have missed to put the node reference using of_node_put() after we are done using the node. This patch fixes it.
Note:
This problem is stated in Link: https://lkml.org/lkml/2018/12/22/217
--- drivers/net/ethernet/hisilicon/hns/hns_enet.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/hisilicon/hns/hns_enet.c +5 -0
@@ -2419,6 +2419,8 @@ static int hns_nic_dev_probe(struct platform_device *pdev) out_notify_fail: (void )cancel_work_sync (&priv->service_task); out_read_prop_fail: +/* safe for ACPI FW */ +of_node_put (to_of_node (priv->fwnode));free_netdev (ndev);return ret; }
@@ -2448,6 +2450,9 @@ static int hns_nic_dev_remove(struct platform_device *pdev)set_bit (NIC_STATE_REMOVING , &priv->state); (void )cancel_work_sync (&priv->service_task); +/* safe for ACPI FW */ +of_node_put (to_of_node (priv->fwnode)); +free_netdev (ndev);return 0 ; }
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 25/65 iomap: get/put the page in iomap_page_create/release()
In reply to Sasha LevinFrom: Piotr Jaroszynski <[email protected]>
[ Upstream commit 8e47a457321ca1a74ad194ab5dcbca764bc70731 ]
migrate_page_move_mapping() expects pages with private data set to have a page_count elevated by 1. This is what used to happen for xfs through the buffer_heads code before the switch to iomap in commit 82cb14175e7d ("xfs: add support for sub-pagesize writeback without buffer_heads"). Not having the count elevated causes move_pages() to fail on memory mapped files coming from xfs.
Make iomap compatible with the migrate_page_move_mapping() assumption by elevating the page count as part of iomap_page_create() and lowering it in iomap_page_release().
It causes the move_pages() syscall to misbehave on memory mapped files from xfs. It does not not move any pages, which I suppose is "just" a perf issue, but it also ends up returning a positive number which is out of spec for the syscall. Talking to Michal Hocko, it sounds like returning positive numbers might be a necessary update to move_pages() anyway though.
[hch: actually get/put the page iomap_migrate_page() to make it work
properly]
--- fs/iomap.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/iomap.c +9 -0
@@ -117,6 +117,12 @@ iomap_page_create(struct inode *inode, struct page *page)atomic_set (&iop->read_count,0 );atomic_set (&iop->write_count,0 );bitmap_zero (iop->uptodate,PAGE_SIZE /SECTOR_SIZE ); + +/* +* migrate_page_move_mapping() assumes that pages with private data have +* their count elevated by 1. +*/ +get_page (page);set_page_private (page, (unsigned long )iop);SetPagePrivate (page);return iop;
@@ -133,6 +139,7 @@ iomap_page_release(struct page *page)WARN_ON_ONCE (atomic_read (&iop->write_count));ClearPagePrivate (page);set_page_private (page,0 ); +put_page (page);kfree (iop); }
@@ -565,8 +572,10 @@ iomap_migrate_page(struct address_space *mapping, struct page *newpage,if (page_has_private (page)) {ClearPagePrivate (page); +get_page (newpage);set_page_private (newpage,page_private (page));set_page_private (page,0 ); +put_page (page);SetPagePrivate (newpage); }
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 24/65 xtensa: SMP: mark each possible CPU as present
In reply to Sasha LevinFrom: Max Filippov <[email protected]>
[ Upstream commit 8b1c42cdd7181200dc1fff39dcb6ac1a3fac2c25 ]
Otherwise it is impossible to enable CPUs after booting with 'maxcpus' parameter.
--- arch/xtensa/kernel/smp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/xtensa/kernel/smp.c +1 -1
@@ -83,7 +83,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus) {unsigned i; -for (i =0 ; i < max_cpus; ++i) +for_each_possible_cpu (i)set_cpu_present (i, true); }
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 26/65 iomap: fix a use after free in iomap_dio_rw
In reply to Sasha LevinFrom: Christoph Hellwig <[email protected]>
[ Upstream commit 4ea899ead2786a30aaa8181fefa81a3df4ad28f6 ]
Introduce a local wait_for_completion variable to avoid an access to the potentially freed dio struture after dropping the last reference count.
Also use the chance to document the completion behavior to make the refcounting clear to the reader of the code.
--- fs/iomap.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
fs/iomap.c +21 -7
@@ -1787,6 +1787,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,loff_t pos = iocb->ki_pos, start = pos;loff_t end = iocb->ki_pos + count -1 , ret =0 ;unsigned int flags =IOMAP_DIRECT ; +bool wait_for_completion =is_sync_kiocb (iocb);struct blk_plug plug;struct iomap_dio *dio;
@@ -1806,7 +1807,6 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, dio->end_io = end_io; dio->error =0 ; dio->flags =0 ; - dio->wait_for_completion =is_sync_kiocb (iocb); dio->submit.iter = iter; dio->submit.waiter = current;
@@ -1861,7 +1861,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,dio_warn_stale_pagecache (iocb->ki_filp); ret =0 ; -if (iov_iter_rw (iter) ==WRITE && !dio->wait_for_completion && +if (iov_iter_rw (iter) ==WRITE && !wait_for_completion && !inode->i_sb->s_dio_done_wq) { ret =sb_init_dio_done_wq (inode->i_sb);if (ret <0 )
@@ -1877,7 +1877,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,if (ret <=0 ) {/* magic error code to fall back to buffered I/O */ if (ret == -ENOTBLK ) { - dio->wait_for_completion = true; + wait_for_completion = true; ret =0 ; }break ;
@@ -1899,8 +1899,24 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,if (dio->flags &IOMAP_DIO_WRITE_FUA ) dio->flags &= ~IOMAP_DIO_NEED_SYNC ; +/* +* We are about to drop our additional submission reference, which +* might be the last reference to the dio. There are three three +* different ways we can progress here: +* +* (a) If this is the last reference we will always complete and free +* the dio ourselves. +* (b) If this is not the last reference, and we serve an asynchronous +* iocb, we must never touch the dio after the decrement, the +* I/O completion handler will complete and free it. +* (c) If this is not the last reference, but we serve a synchronous +* iocb, the I/O completion handler will wake us up on the drop +* of the final reference, and we will complete and free it here +* after we got woken by the I/O completion handler. +*/ + dio->wait_for_completion = wait_for_completion;if (!atomic_dec_and_test (&dio->ref)) { -if (!dio->wait_for_completion) +if (!wait_for_completion)return -EIOCBQUEUED ;for (;;) {
@@ -1917,9 +1933,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,__set_current_state (TASK_RUNNING ); } - ret =iomap_dio_complete (dio); - -return ret; +return iomap_dio_complete (dio); out_free_dio:kfree (dio);
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 18/65 xtensa: SMP: fix ccount_timer_shutdown
In reply to Sasha LevinFrom: Max Filippov <[email protected]>
[ Upstream commit 4fe8713b873fc881284722ce4ac47995de7cf62c ]
ccount_timer_shutdown is called from the atomic context in the secondary_start_kernel, resulting in the following BUG:
BUG: sleeping function called from invalid context in_atomic(): 1, irqs_disabled(): 1, pid: 0, name: swapper/1 Preemption disabled at: secondary_start_kernel+0xa1/0x130 Call Trace: ___might_sleep+0xe7/0xfc __might_sleep+0x41/0x44 synchronize_irq+0x24/0x64 disable_irq+0x11/0x14 ccount_timer_shutdown+0x12/0x20 clockevents_switch_state+0x82/0xb4 clockevents_exchange_device+0x54/0x60 tick_check_new_device+0x46/0x70 clockevents_register_device+0x8c/0xc8 clockevents_config_and_register+0x1d/0x2c local_timer_setup+0x75/0x7c secondary_start_kernel+0xb4/0x130 should_never_return+0x32/0x35
Use disable_irq_nosync instead of disable_irq to avoid it. This is safe because the ccount timer IRQ is per-CPU, and once IRQ is masked the ISR will not be called.
--- arch/xtensa/kernel/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/xtensa/kernel/time.c +1 -1
@@ -89,7 +89,7 @@ static int ccount_timer_shutdown(struct clock_event_device *evt) container_of(evt, struct ccount_timer, evt);if (timer->irq_enabled) { -disable_irq (evt->irq); +disable_irq_nosync (evt->irq); timer->irq_enabled =0 ; }return 0 ;
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 8/65 perf tools: Handle TOPOLOGY headers with no CPU
In reply to Sasha LevinFrom: Stephane Eranian <[email protected]>
[ Upstream commit 1497e804d1a6e2bd9107ddf64b0310449f4673eb ]
This patch fixes an issue in cpumap.c when used with the TOPOLOGY header. In some configurations, some NUMA nodes may have no CPU (empty cpulist). Yet a cpumap map must be created otherwise perf abort with an error. This patch handles this case by creating a dummy map.
Before:
$ perf record -o - -e cycles noploop 2 | perf script -i - 0x6e8 [0x6c]: failed to process type: 80
After:
$ perf record -o - -e cycles noploop 2 | perf script -i - noploop for 2 seconds
--- tools/perf/util/cpumap.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tools/perf/util/cpumap.c +9 -2
@@ -134,7 +134,12 @@ struct cpu_map *cpu_map__new(const char *cpu_list)if (!cpu_list)return cpu_map__read_all_cpu_map (); -if (!isdigit (*cpu_list)) +/* +* must handle the case of empty cpumap to cover +* TOPOLOGY header for NUMA nodes with no CPU +* ( e.g., because of CPU hotplug) +*/ +if (!isdigit (*cpu_list) && *cpu_list !='\0' ) goto out;while (isdigit (*cpu_list)) {
@@ -181,8 +186,10 @@ struct cpu_map *cpu_map__new(const char *cpu_list)if (nr_cpus >0 ) cpus =cpu_map__trim_new (nr_cpus, tmp_cpus); -else +else if (*cpu_list !='\0' ) cpus =cpu_map__default_new (); +else + cpus =cpu_map__dummy_new (); invalid:free (tmp_cpus); out:
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 7/65 perf core: Fix perf_proc_update_handler() bug
In reply to Sasha LevinFrom: Stephane Eranian <[email protected]>
[ Upstream commit 1a51c5da5acc6c188c917ba572eebac5f8793432 ]
The perf_proc_update_handler() handles /proc/sys/kernel/perf_event_max_sample_rate syctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e, when /proc/sys/kernel/perf_cpu_time_max_percent is equal to 0 or 100, then no modification to sysctl_perf_event_sample_rate is allowed to prevent possible hang from wrong values.
The problem is that the test to prevent modification is made after the sysctl variable is modified in perf_proc_update_handler().
You get an error:
$ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate echo: write error: invalid argument
But the value is still modified causing all sorts of inconsistencies:
$ cat /proc/sys/kernel/perf_event_max_sample_rate 10001
This patch fixes the problem by moving the parsing of the value after the test.
Committer testing:
# echo 100 > /proc/sys/kernel/perf_cpu_time_max_percent # echo 10001 > /proc/sys/kernel/perf_event_max_sample_rate -bash: echo: write error: Invalid argument # cat /proc/sys/kernel/perf_event_max_sample_rate 10001 #
--- kernel/events/core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
kernel/events/core.c +7 -7
@@ -436,18 +436,18 @@ int perf_proc_update_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { - int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); - -if (ret || !write) -return ret; - + int ret; +int perf_cpu = sysctl_perf_cpu_time_max_percent;/* * If throttling is disabled don't allow the write: */ -if (sysctl_perf_cpu_time_max_percent ==100 || - sysctl_perf_cpu_time_max_percent ==0 ) +if (write && (perf_cpu ==100 || perf_cpu ==0 ))return -EINVAL ; + ret =proc_dointvec_minmax (table, write, buffer, lenp, ppos); +if (ret || !write) +return ret; + max_samples_per_tick =DIV_ROUND_UP (sysctl_perf_event_sample_rate,HZ ); perf_sample_period_ns =NSEC_PER_SEC / sysctl_perf_event_sample_rate;update_perf_cpu_limits ();
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 6/65 perf script: Fix crash with printing mixed trace point and other events
In reply to Sasha LevinFrom: Andi Kleen <[email protected]>
[ Upstream commit 96167167b6e17b25c0e05ecc31119b73baeab094 ]
'perf script' crashes currently when printing mixed trace points and other events because the trace format does not handle events without trace meta data. Add a simple check to avoid that.
% cat > test.c
main()
{
printf("Hello world\n");
}
^D
% gcc -g -o test test.c
% sudo perf probe -x test 'test.c:3'
% perf record -e '{cpu/cpu-cycles,period=10000/,probe_test:main}:S' ./test
% perf script
<segfault>Committer testing:
Before:
# perf probe -x /lib64/libc-2.28.so malloc
Added new event:
probe_libc:malloc (on malloc in /usr/lib64/libc-2.28.so)You can now use it in all perf tools, such as:
perf record -e probe_libc:malloc -aR sleep 1
# perf probe -l
probe_libc:malloc (on __libc_malloc@malloc/malloc.c in /usr/lib64/libc-2.28.so)
# perf record -e '{cpu/cpu-cycles,period=10000/,probe_libc:*}:S' sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.023 MB perf.data (40 samples) ]
# perf script
Segmentation fault (core dumped)
^C
#After:
# perf script | head -6
sleep 2888 94796.944981: 16198 cpu/cpu-cycles,period=10000/: ffffffff925dc04f get_random_u32+0x1f (/lib/modules/5.0.0-rc2+/build/vmlinux)
sleep 2888 [-01] 94796.944981: probe_libc:malloc:
sleep 2888 94796.944983: 4713 cpu/cpu-cycles,period=10000/: ffffffff922763af change_protection+0xcf (/lib/modules/5.0.0-rc2+/build/vmlinux)
sleep 2888 [-01] 94796.944983: probe_libc:malloc:
sleep 2888 94796.944986: 9934 cpu/cpu-cycles,period=10000/: ffffffff922777e0 move_page_tables+0x0 (/lib/modules/5.0.0-rc2+/build/vmlinux)
sleep 2888 [-01] 94796.944986: probe_libc:malloc:
#--- tools/perf/builtin-script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-script.c +1 -1
@@ -1658,7 +1658,7 @@ static void process_event(struct perf_script *script,return ; } -if (PRINT_FIELD (TRACE )) { +if (PRINT_FIELD (TRACE ) && sample->raw_data) {event_format__fprintf (evsel->tp_format, sample->cpu, sample->raw_data, sample->raw_size, fp); }
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 4/65 netfilter: nft_compat: use refcnt_t type for nft_xt reference count
In reply to Sasha LevinFrom: Florian Westphal <[email protected]>
[ Upstream commit 12c44aba6618b7f6c437076e5722237190f6cd5f ]
Using standard integer type was fine while all operations on it were guarded by the nftnl subsys mutex.
This isn't true anymore:
1. transactions are guarded only by a pernet mutex, so concurrent rule manipulation in different netns is racy
2. the ->destroy hook runs from a work queue after the transaction mutex has been released already.
cpu0 cpu1 (net 1) cpu2 (net 2)
kworker
nft_compat->destroy nft_compat->init nft_compat->init
if (--nft_xt->ref == 0) nft_xt->ref++ nft_xt->ref++Switch to refcount_t. Doing this however only fixes a minor aspect, nft_compat also performs linked-list operations in an unsafe way.
This is addressed in the next two patches.
--- net/netfilter/nft_compat.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
net/netfilter/nft_compat.c +8 -8
@@ -26,7 +26,7 @@struct nft_xt {struct list_head head;struct nft_expr_ops ops; -unsigned int refcnt; +refcount_t refcnt;/* Unlike other expressions, ops doesn't have static storage duration. * nft core assumes they do. We use kfree_rcu so that nft core can
@@ -45,7 +45,7 @@ struct nft_xt_match_priv {static bool nft_xt_put (struct nft_xt *xt) { -if (--xt->refcnt ==0 ) { +if (refcount_dec_and_test (&xt->refcnt)) {list_del (&xt->head);kfree_rcu (xt, rcu_head);return true;
@@ -273,7 +273,7 @@ nft_target_init(const struct nft_ctx *ctx, const struct nft_expr *expr,return -EINVAL ; nft_xt = container_of(expr->ops, struct nft_xt, ops); - nft_xt->refcnt++; +refcount_inc (&nft_xt->refcnt);return 0 ; }
@@ -467,7 +467,7 @@ __nft_match_init(const struct nft_ctx *ctx, const struct nft_expr *expr,return ret; nft_xt = container_of(expr->ops, struct nft_xt, ops); - nft_xt->refcnt++; +refcount_inc (&nft_xt->refcnt);return 0 ; }
@@ -769,7 +769,7 @@ nft_match_select_ops(const struct nft_ctx *ctx, goto err; } - nft_match->refcnt =0 ; +refcount_set (&nft_match->refcnt,0 ); nft_match->ops.type = &nft_match_type; nft_match->ops.eval = nft_match_eval; nft_match->ops.init = nft_match_init;
@@ -873,7 +873,7 @@ nft_target_select_ops(const struct nft_ctx *ctx, goto err; } - nft_target->refcnt =0 ; +refcount_set (&nft_target->refcnt,0 ); nft_target->ops.type = &nft_target_type; nft_target->ops.size =NFT_EXPR_SIZE (XT_ALIGN (target->targetsize)); nft_target->ops.init = nft_target_init;
@@ -944,7 +944,7 @@ static void __exit nft_compat_module_exit(void)list_for_each_entry_safe (xt, next, &nft_target_list, head) {struct xt_target *target = xt->ops.data; -if (WARN_ON_ONCE (xt->refcnt)) +if (WARN_ON_ONCE (refcount_read (&xt->refcnt)))continue ;module_put (target->me);kfree (xt);
@@ -953,7 +953,7 @@ static void __exit nft_compat_module_exit(void)list_for_each_entry_safe (xt, next, &nft_match_list, head) {struct xt_match *match = xt->ops.data; -if (WARN_ON_ONCE (xt->refcnt)) +if (WARN_ON_ONCE (refcount_read (&xt->refcnt)))continue ;module_put (match->me);kfree (xt);
Signature · 1 line
2.19.1
Sasha Levin
maintainerPATCH 2/65 xfrm: refine validation of template and selector families
In reply to Sasha LevinFrom: Florian Westphal <[email protected]>
[ Upstream commit 35e6103861a3a970de6c84688c6e7a1f65b164ca ]
The check assumes that in transport mode, the first templates family must match the address family of the policy selector.
Syzkaller managed to build a template using MODE_ROUTEOPTIMIZATION, with ipv4-in-ipv6 chain, leading to following splat:
BUG: KASAN: stack-out-of-bounds in xfrm_state_find+0x1db/0x1854 Read of size 4 at addr ffff888063e57aa0 by task a.out/2050 xfrm_state_find+0x1db/0x1854 xfrm_tmpl_resolve+0x100/0x1d0 xfrm_resolve_and_create_bundle+0x108/0x1000 [..]
Problem is that addresses point into flowi4 struct, but xfrm_state_find treats them as being ipv6 because it uses templ->encap_family is used (AF_INET6 in case of reproducer) rather than family (AF_INET).
This patch inverts the logic: Enforce 'template family must match selector' EXCEPT for tunnel and BEET mode.
In BEET and Tunnel mode, xfrm_tmpl_resolve_one will have remote/local address pointers changed to point at the addresses found in the template, rather than the flowi ones, so no oob read will occur.
--- net/xfrm/xfrm_user.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
net/xfrm/xfrm_user.c +9 -4
@@ -1488,10 +1488,15 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)if (!ut[i].family) ut[i].family = family; -if ((ut[i].mode ==XFRM_MODE_TRANSPORT ) && - (ut[i].family != prev_family)) -return -EINVAL ; - +switch (ut[i].mode) { +case XFRM_MODE_TUNNEL : +case XFRM_MODE_BEET : +break ; +default : +if (ut[i].family != prev_family) +return -EINVAL ; +break ; + }if (ut[i].mode >=XFRM_MODE_MAX )return -EINVAL ;
Signature · 1 line
2.19.1