From: Eric Dumazet <edumazet(a)google.com>
commit 190cc82489f46f9d88e73c81a47e14f80a791e1a upstream
RFC 6056 (Recommendations for Transport-Protocol Port Randomization)
provides good summary of why source selection needs extra care.
David Dworken reminded us that linux implements Algorithm 3
as described in RFC 6056 3.3.3
Quoting David :
In the context of the web, this creates an interesting info leak where
websites can count how many TCP connections a user's computer is
establishing over time. For example, this allows a website to count
exactly how many subresources a third party website loaded.
This also allows:
- Distinguishing between different users behind a VPN based on
distinct source port ranges.
- Tracking users over time across multiple networks.
- Covert communication channels between different browsers/browser
profiles running on the same computer
- Tracking what applications are running on a computer based on
the pattern of how fast source ports are getting incremented.
Section 3.3.4 describes an enhancement, that reduces
attackers ability to use the basic information currently
stored into the shared 'u32 hint'.
This change also decreases collision rate when
multiple applications need to connect() to
different destinations.
Signed-off-by: Eric Dumazet <edumazet(a)google.com>
Reported-by: David Dworken <ddworken(a)google.com>
Cc: Willem de Bruijn <willemb(a)google.com>
Signed-off-by: David S. Miller <davem(a)davemloft.net>
[SG: Adjusted context]
Signed-off-by: Stefan Ghinea <stefan.ghinea(a)windriver.com>
---
net/ipv4/inet_hashtables.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 1346e45cf8d1..0bc6549c38b1 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -587,6 +587,17 @@ void inet_unhash(struct sock *sk)
}
EXPORT_SYMBOL_GPL(inet_unhash);
+/* RFC 6056 3.3.4. Algorithm 4: Double-Hash Port Selection Algorithm
+ * Note that we use 32bit integers (vs RFC 'short integers')
+ * because 2^16 is not a multiple of num_ephemeral and this
+ * property might be used by clever attacker.
+ * RFC claims using TABLE_LENGTH=10 buckets gives an improvement,
+ * we use 256 instead to really give more isolation and
+ * privacy, this only consumes 1 KB of kernel memory.
+ */
+#define INET_TABLE_PERTURB_SHIFT 8
+static u32 table_perturb[1 << INET_TABLE_PERTURB_SHIFT];
+
int __inet_hash_connect(struct inet_timewait_death_row *death_row,
struct sock *sk, u32 port_offset,
int (*check_established)(struct inet_timewait_death_row *,
@@ -600,7 +611,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
struct inet_bind_bucket *tb;
u32 remaining, offset;
int ret, i, low, high;
- static u32 hint;
+ u32 index;
if (port) {
head = &hinfo->bhash[inet_bhashfn(net, port,
@@ -625,7 +636,10 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
if (likely(remaining > 1))
remaining &= ~1U;
- offset = (hint + port_offset) % remaining;
+ net_get_random_once(table_perturb, sizeof(table_perturb));
+ index = hash_32(port_offset, INET_TABLE_PERTURB_SHIFT);
+
+ offset = (READ_ONCE(table_perturb[index]) + port_offset) % remaining;
/* In first pass we try ports of @low parity.
* inet_csk_get_port() does the opposite choice.
*/
@@ -678,7 +692,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
return -EADDRNOTAVAIL;
ok:
- hint += i + 2;
+ WRITE_ONCE(table_perturb[index], READ_ONCE(table_perturb[index]) + i + 2);
/* Head lock still held and bh's disabled */
inet_bind_hash(sk, tb, port);
--
2.36.1
From: Magnus Karlsson <magnus.karlsson(a)intel.com>
Fix a crash in the zero-copy driver that occurs when it fails to
allocate buffers from user-space. This crash can easily be triggered
by a malicious program that does not provide any buffers in the fill
ring for the kernel to use.
Note that this bug does not exist in upstream since the batched buffer
allocation interface got introduced in 5.16 and replaced this code.
Reported-by: Jeff Shaw <jeffrey.b.shaw(a)intel.com>
Tested-by: Jeff Shaw <jeffrey.b.shaw(a)intel.com>
Signed-off-by: Magnus Karlsson <magnus.karlsson(a)intel.com>
---
drivers/net/ethernet/intel/ice/ice_xsk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_xsk.c b/drivers/net/ethernet/intel/ice/ice_xsk.c
index 2b1873061912..5581747947e5 100644
--- a/drivers/net/ethernet/intel/ice/ice_xsk.c
+++ b/drivers/net/ethernet/intel/ice/ice_xsk.c
@@ -378,7 +378,7 @@ bool ice_alloc_rx_bufs_zc(struct ice_ring *rx_ring, u16 count)
do {
*xdp = xsk_buff_alloc(rx_ring->xsk_pool);
- if (!xdp) {
+ if (!*xdp) {
ok = false;
break;
}
base-commit: 9f43e3ac7e662f352f829077723fa0b92ccaded1
--
2.34.1
The patch below does not apply to the 5.17-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable(a)vger.kernel.org>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 9f46c187e2e680ecd9de7983e4d081c3391acc76 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <pbonzini(a)redhat.com>
Date: Fri, 20 May 2022 13:48:11 -0400
Subject: [PATCH] KVM: x86/mmu: fix NULL pointer dereference on guest INVPCID
With shadow paging enabled, the INVPCID instruction results in a call
to kvm_mmu_invpcid_gva. If INVPCID is executed with CR0.PG=0, the
invlpg callback is not set and the result is a NULL pointer dereference.
Fix it trivially by checking for mmu->invlpg before every call.
There are other possibilities:
- check for CR0.PG, because KVM (like all Intel processors after P5)
flushes guest TLB on CR0.PG changes so that INVPCID/INVLPG are a
nop with paging disabled
- check for EFER.LMA, because KVM syncs and flushes when switching
MMU contexts outside of 64-bit mode
All of these are tricky, go for the simple solution. This is CVE-2022-1789.
Reported-by: Yongkang Jia <kangel(a)zju.edu.cn>
Cc: stable(a)vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini(a)redhat.com>
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 56ebc4fb7f91..45e1573f8f1d 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -5470,14 +5470,16 @@ void kvm_mmu_invpcid_gva(struct kvm_vcpu *vcpu, gva_t gva, unsigned long pcid)
uint i;
if (pcid == kvm_get_active_pcid(vcpu)) {
- mmu->invlpg(vcpu, gva, mmu->root.hpa);
+ if (mmu->invlpg)
+ mmu->invlpg(vcpu, gva, mmu->root.hpa);
tlb_flush = true;
}
for (i = 0; i < KVM_MMU_NUM_PREV_ROOTS; i++) {
if (VALID_PAGE(mmu->prev_roots[i].hpa) &&
pcid == kvm_get_pcid(vcpu, mmu->prev_roots[i].pgd)) {
- mmu->invlpg(vcpu, gva, mmu->prev_roots[i].hpa);
+ if (mmu->invlpg)
+ mmu->invlpg(vcpu, gva, mmu->prev_roots[i].hpa);
tlb_flush = true;
}
}
Hi,
I would like to kindly request the inclusion of commit 24ef83f6e31d
("Input: goodix - fix spurious key release events") to the 5.4 stable
tree.
It fixes the spurious touches reported on an imx6dl board with Goodix
GT911 running kernel 5.4.
Thanks,
Fabio Estevam
[Public]
Hi,
The firmware on some OEM laptops with AMD SOCs advertise that they have sensors connected to AMD SFH but they really don't
physically have them. In 5.19 a commit has gone in that discovers this case and prevents the driver from advertising this sensor
to userspace. This might not seem like a big deal to have sensors advertised that aren't really there, but AMD has observed
that specifically on orientation sensors the random garbage data associated can cause userspace to interpret a screen rotation
during resume from suspend.
As GNOME has a daemon running that interprets these events I've seen first hand that it can cause the display go upside down
without a lot of recourse other than command line tools or rebooting.
Can you please backport this commit to 5.15.y+ and later to fix this:
commit b5d7f43e97dabfa04a4be5ff027ce7da119332be ("HID: amd_sfh: Add support for sensor discovery")
Thanks,
The routine huge_pmd_unshare is passed a pointer to an address
associated with an area which may be unshared. If unshare is successful
this address is updated to 'optimize' callers iterating over huge page
addresses. For the optimization to work correctly, address should be
updated to the last huge page in the unmapped/unshared area. However,
in the common case where the passed address is PUD_SIZE aligned, the
address is incorrectly updated to the address of the preceding huge
page. That wastes CPU cycles as the unmapped/unshared range is scanned
twice.
Cc: <stable(a)vger.kernel.org>
Fixes: 39dde65c9940 ("shared page table for hugetlb page")
Signed-off-by: Mike Kravetz <mike.kravetz(a)oracle.com>
---
mm/hugetlb.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 01f0e2e5ab48..7c468ac1d069 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6755,7 +6755,14 @@ int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma,
pud_clear(pud);
put_page(virt_to_page(ptep));
mm_dec_nr_pmds(mm);
- *addr = ALIGN(*addr, HPAGE_SIZE * PTRS_PER_PTE) - HPAGE_SIZE;
+ /*
+ * This update of passed address optimizes loops sequentially
+ * processing addresses in increments of huge page size (PMD_SIZE
+ * in this case). By clearing the pud, a PUD_SIZE area is unmapped.
+ * Update address to the 'last page' in the cleared area so that
+ * calling loop can move to first page past this area.
+ */
+ *addr |= PUD_SIZE - PMD_SIZE;
return 1;
}
--
2.35.3
Resending this because stable(a)vger.kernel.org using wrong header field.
Apologize for duplicates.
On Thu, 19 May 2022 09:52:07 -0400
Sasha Levin <sashal(a)kernel.org> wrote:
> This is a note to let you know that I've just added the patch titled
>
> um: port_user: Improve error handling when port-helper is not found
>
> to the 5.17-stable tree which can be found at:
> http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=sum…
>
> The filename of the patch is:
> um-port_user-improve-error-handling-when-port-helper.patch
> and it can be found in the queue-5.17 subdirectory.
>
> If you, or anyone else, feels it should not be added to the stable tree,
> please let <stable(a)vger.kernel.org> know about it.
First, I should say that I'm not familiar with the process so I'm
likely to be wrong on any number of things. Second I'm the author of
this patch and I would like to see this included in the stable trees.
However, it appears to me that there is a problem in including just this
patch, as it depends on a previous patch which does not appear to be
applied[1].
> commit efc324ad7e7e1c92a8862bd71b2f5f8f15513304
> Author: Glenn Washburn <development(a)efficientek.com>
> Date: Thu Mar 3 01:53:32 2022 -0600
>
> um: port_user: Improve error handling when port-helper is not found
>
> [ Upstream commit 3cb5a7f167c620a8b0e38b0446df2e024d2243dc ]
>
> Check if port-helper exists and is executable. If not, write an error
> message to the kernel log with information to help the user diagnose the
> issue and exit with an error. If UML_PORT_HELPER was not set, write a
> message suggesting that the user set it. This makes it easier to understand
> why telneting to the UML instance is failing and what can be done to fix it.
>
> Signed-off-by: Glenn Washburn <development(a)efficientek.com>
> Signed-off-by: Richard Weinberger <richard(a)nod.at>
> Signed-off-by: Sasha Levin <sashal(a)kernel.org>
>
> diff --git a/arch/um/drivers/port_user.c b/arch/um/drivers/port_user.c
> index 5b5b64cb1071..133ca7bf2d91 100644
> --- a/arch/um/drivers/port_user.c
> +++ b/arch/um/drivers/port_user.c
> @@ -5,6 +5,7 @@
>
> #include <stdio.h>
> #include <stdlib.h>
> +#include <string.h>
> #include <errno.h>
> #include <termios.h>
> #include <unistd.h>
> @@ -175,6 +176,17 @@ int port_connection(int fd, int *socket, int *pid_out)
> if (new < 0)
> return -errno;
>
> + err = os_access(argv[2], X_OK);
> + if (err < 0) {
> + printk(UM_KERN_ERR "port_connection : error accessing port-helper "
> + "executable at %s: %s\n", argv[2], strerror(-err));
> + if (env == NULL)
The the afore mentioned patch that this patch depends on "env" is
declared and set. Without it, I'd expect this to fail to compile. As
such, I may be wrong in that the dependent patch was not already
included because I'd expect there to have been a compile test prior to
this patch getting to this phase.
My suspicion is that the stable trees try to not include new
functionality, which the missing patch may have been considered to have
done, and thus was not included. If its deemed undesirable to include
the missing patch, this "if" block can be removed. Although, I think
the missing patch is valuable enough to include.
The above goes for all the stable branches that this patch is set to be
included in.
Glenn
[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?…
> + printk(UM_KERN_ERR "Set UML_PORT_HELPER environment "
> + "variable to path to uml-utilities port-helper "
> + "binary\n");
> + goto out_close;
> + }
> +
> err = os_pipe(socket, 0, 0);
> if (err < 0)
> goto out_close;