Blame SOURCES/CVE-2023-3611.patch

b5132d
From d899fb6f8a4b6370576e3a009e959bc98ee03c16 Mon Sep 17 00:00:00 2001
b5132d
From: Ryan Sullivan <rysulliv@redhat.com>
b5132d
Date: Mon, 16 Oct 2023 14:08:36 -0400
b5132d
Subject: [KPATCH CVE-2023-3611] kpatch fixes for CVE-2023-3611
b5132d
b5132d
Kernels:
b5132d
3.10.0-1160.90.1.el7
b5132d
3.10.0-1160.92.1.el7
b5132d
3.10.0-1160.95.1.el7
b5132d
3.10.0-1160.99.1.el7
b5132d
3.10.0-1160.102.1.el7
b5132d
b5132d
b5132d
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-7/-/merge_requests/60
b5132d
Approved-by: Joe Lawrence (@joe.lawrence)
b5132d
Approved-by: Yannick Cote (@ycote1)
b5132d
Changes since last build:
b5132d
arches: x86_64 ppc64le
b5132d
cls_fw.o: changed function: fw_change
b5132d
cls_fw.o: changed function: fw_set_parms
b5132d
cls_route.o: changed function: route4_change
b5132d
cls_u32.o: changed function: u32_change
b5132d
sch_qfq.o: changed function: qfq_enqueue
b5132d
---------------------------
b5132d
b5132d
Modifications: none
b5132d
b5132d
commit 726e9f3d88c729cdae09768c94e588deebdb9d52
b5132d
Author: Marcelo Tosatti <mtosatti@redhat.com>
b5132d
Date:   Mon Jan 23 17:17:17 2023 -0300
b5132d
b5132d
    KVM: x86: rename argument to kvm_set_tsc_khz
b5132d
b5132d
    commit 4941b8cb3746f09bb102f7a5d64d878e96a0c6cd
b5132d
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2152838
b5132d
    JIRA: https://issues.redhat.com/browse/RHELPLAN-141963
b5132d
    Testing: Tested by QE
b5132d
b5132d
    This refers to the desired (scaled) frequency, which is called
b5132d
    user_tsc_khz in the rest of the file.
b5132d
b5132d
    Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
b5132d
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
b5132d
    Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
b5132d
b5132d
commit 866faa0e99083ee93d04d3c37065cf8dbfc51a34
b5132d
Author: Marcelo Tosatti <mtosatti@redhat.com>
b5132d
Date:   Mon Jan 23 17:24:19 2023 -0300
b5132d
b5132d
    KVM: x86: rewrite handling of scaled TSC for kvmclock
b5132d
b5132d
    commit 78db6a5037965429c04d708281f35a6e5562d31b
b5132d
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2152838
b5132d
    Testing: Tested by QE
b5132d
    JIRA: https://issues.redhat.com/browse/RHELPLAN-141963
b5132d
b5132d
    This is the same as before:
b5132d
b5132d
        kvm_scale_tsc(tgt_tsc_khz)
b5132d
            = tgt_tsc_khz * ratio
b5132d
            = tgt_tsc_khz * user_tsc_khz / tsc_khz   (see set_tsc_khz)
b5132d
            = user_tsc_khz                           (see kvm_guest_time_update)
b5132d
            = vcpu->arch.virtual_tsc_khz             (see kvm_set_tsc_khz)
b5132d
b5132d
    However, computing it through kvm_scale_tsc will make it possible
b5132d
    to include the NTP correction in tgt_tsc_khz.
b5132d
b5132d
    Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
b5132d
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
b5132d
    Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
b5132d
b5132d
commit bde6eebb5708ecd38db0023e657d38058e0d962f
b5132d
Author: Marcelo Tosatti <mtosatti@redhat.com>
b5132d
Date:   Wed Jan 25 16:07:18 2023 -0300
b5132d
b5132d
    KVM: x86: add bit to indicate correct tsc_shift
b5132d
b5132d
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2152838
b5132d
    Testing: Tested by QE
b5132d
    Upstream Status: RHEL7 only
b5132d
    JIRA: https://issues.redhat.com/browse/RHELPLAN-141963
b5132d
b5132d
    This changeset is unique to RHEL-7 since it was decided
b5132d
    it is not necessary upstream:
b5132d
b5132d
    "I don't think it's justifiable to further complicate the userspace API for a
b5132d
    bug that's been fixed six years ago.  I'd be very surprised if any combination
b5132d
    of modern upstream {QEMU,kernel} is going to do a successful migration from
b5132d
    such an old {QEMU,kernel}.  RHEL/CentOS are able to do so because *specific
b5132d
    pairs* have been tested, but as far as upstream is concerned this adds
b5132d
    complexity that absolutely no one will use."
b5132d
b5132d
    Before commit 78db6a5037965429c04d708281f35a6e5562d31b,
b5132d
    kvm_guest_time_update() would use vcpu->virtual_tsc_khz to calculate
b5132d
    tsc_shift value in the vcpus pvclock structure written to guest memory.
b5132d
b5132d
    For those kernels, if vcpu->virtual_tsc_khz != tsc_khz (which can be the
b5132d
    case when guest state is restored via migration, or if tsc-khz option is
b5132d
    passed to QEMU), and TSC scaling is not enabled (which happens if the
b5132d
    difference between the frequency requested via KVM_SET_TSC_KHZ and the
b5132d
    host TSC KHZ is smaller than 250ppm), then there can be a difference
b5132d
    between what KVM_GET_CLOCK would return and what the guest reads as
b5132d
    kvmclock value.
b5132d
b5132d
    When KVM_SET_CLOCK'ing what is read with KVM_GET_CLOCK, the
b5132d
    guest can observe a forward or backwards time jump.
b5132d
b5132d
    Advertise to userspace that current kernel contains
b5132d
    this fix, so QEMU can workaround the problem by reading
b5132d
    pvclock via guest memory directly otherwise.
b5132d
b5132d
    Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
b5132d
b5132d
commit 9dbd3713d82f45c9781f2dc6dd49dc3ee07ba980
b5132d
Author: Davide Caratti <dcaratti@redhat.com>
b5132d
Date:   Tue Aug 8 12:55:43 2023 +0200
b5132d
b5132d
    net/sched: sch_qfq: account for stab overhead in qfq_enqueue
b5132d
b5132d
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2225555
b5132d
    CVE: CVE-2023-3611
b5132d
    Upstream Status: net.git commit 3e337087c3b5
b5132d
    Conflicts:
b5132d
     - we don't have QFQ_MAX_LMAX defined in rhel-7 because of
b5132d
       missing upstream commit 25369891fcef ("net/sched: sch_qfq:
b5132d
       refactor parsing of netlink parameters"): use its value in
b5132d
       the test inside qfq_change_agg()
b5132d
b5132d
    commit 3e337087c3b5805fe0b8a46ba622a962880b5d64
b5132d
    Author: Pedro Tammela <pctammela@mojatatu.com>
b5132d
    Date:   Tue Jul 11 18:01:02 2023 -0300
b5132d
b5132d
        net/sched: sch_qfq: account for stab overhead in qfq_enqueue
b5132d
b5132d
        Lion says:
b5132d
        -------
b5132d
        In the QFQ scheduler a similar issue to CVE-2023-31436
b5132d
        persists.
b5132d
b5132d
        Consider the following code in net/sched/sch_qfq.c:
b5132d
b5132d
        static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch,
b5132d
                        struct sk_buff **to_free)
b5132d
        {
b5132d
             unsigned int len = qdisc_pkt_len(skb), gso_segs;
b5132d
b5132d
            // ...
b5132d
b5132d
             if (unlikely(cl->agg->lmax < len)) {
b5132d
                 pr_debug("qfq: increasing maxpkt from %u to %u for class %u",
b5132d
                      cl->agg->lmax, len, cl->common.classid);
b5132d
                 err = qfq_change_agg(sch, cl, cl->agg->class_weight, len);
b5132d
                 if (err) {
b5132d
                     cl->qstats.drops++;
b5132d
                     return qdisc_drop(skb, sch, to_free);
b5132d
                 }
b5132d
b5132d
            // ...
b5132d
b5132d
             }
b5132d
b5132d
        Similarly to CVE-2023-31436, "lmax" is increased without any bounds
b5132d
        checks according to the packet length "len". Usually this would not
b5132d
        impose a problem because packet sizes are naturally limited.
b5132d
b5132d
        This is however not the actual packet length, rather the
b5132d
        "qdisc_pkt_len(skb)" which might apply size transformations according to
b5132d
        "struct qdisc_size_table" as created by "qdisc_get_stab()" in
b5132d
        net/sched/sch_api.c if the TCA_STAB option was set when modifying the qdisc.
b5132d
b5132d
        A user may choose virtually any size using such a table.
b5132d
b5132d
        As a result the same issue as in CVE-2023-31436 can occur, allowing heap
b5132d
        out-of-bounds read / writes in the kmalloc-8192 cache.
b5132d
        -------
b5132d
b5132d
        We can create the issue with the following commands:
b5132d
b5132d
        tc qdisc add dev $DEV root handle 1: stab mtu 2048 tsize 512 mpu 0 \
b5132d
        overhead 999999999 linklayer ethernet qfq
b5132d
        tc class add dev $DEV parent 1: classid 1:1 htb rate 6mbit burst 15k
b5132d
        tc filter add dev $DEV parent 1: matchall classid 1:1
b5132d
        ping -I $DEV 1.1.1.2
b5132d
b5132d
        This is caused by incorrectly assuming that qdisc_pkt_len() returns a
b5132d
        length within the QFQ_MIN_LMAX < len < QFQ_MAX_LMAX.
b5132d
b5132d
        Fixes: 462dbc9101ac ("pkt_sched: QFQ Plus: fair-queueing service at DRR cost")
b5132d
        Reported-by: Lion <nnamrec@gmail.com>
b5132d
        Reviewed-by: Eric Dumazet <edumazet@google.com>
b5132d
        Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
b5132d
        Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
b5132d
        Reviewed-by: Simon Horman <simon.horman@corigine.com>
b5132d
        Signed-off-by: Paolo Abeni <pabeni@redhat.com>
b5132d
b5132d
    Signed-off-by: Davide Caratti <dcaratti@redhat.com>
b5132d
b5132d
Signed-off-by: Ryan Sullivan <rysulliv@redhat.com>
b5132d
---
b5132d
 net/sched/sch_qfq.c | 7 ++++++-
b5132d
 1 file changed, 6 insertions(+), 1 deletion(-)
b5132d
b5132d
diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c
b5132d
index a36b3ec3271a..ca8c79456c80 100644
b5132d
--- a/net/sched/sch_qfq.c
b5132d
+++ b/net/sched/sch_qfq.c
b5132d
@@ -387,8 +387,13 @@ static int qfq_change_agg(struct Qdisc *sch, struct qfq_class *cl, u32 weight,
b5132d
 			   u32 lmax)
b5132d
 {
b5132d
 	struct qfq_sched *q = qdisc_priv(sch);
b5132d
-	struct qfq_aggregate *new_agg = qfq_find_agg(q, lmax, weight);
b5132d
+	struct qfq_aggregate *new_agg;
b5132d
 
b5132d
+	/* 'lmax' can range from [QFQ_MIN_LMAX, pktlen + stab overhead] */
b5132d
+	if (lmax > (1UL << QFQ_MTU_SHIFT))
b5132d
+		return -EINVAL;
b5132d
+
b5132d
+	new_agg = qfq_find_agg(q, lmax, weight);
b5132d
 	if (new_agg == NULL) { /* create new aggregate */
b5132d
 		new_agg = kzalloc(sizeof(*new_agg), GFP_ATOMIC);
b5132d
 		if (new_agg == NULL)
b5132d
-- 
b5132d
2.41.0
b5132d
b5132d