From 2bfa25e55c0a49bc079e5769db2199989eda7745 Mon Sep 17 00:00:00 2001 From: Jon Maloy Date: Fri, 11 Dec 2020 00:59:26 -0500 Subject: [PATCH 03/14] slirp: check pkt_len before reading protocol header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RH-Author: Jon Maloy Message-id: <20201211005926.618830-2-jmaloy@redhat.com> Patchwork-id: 100398 O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 1/1] slirp: check pkt_len before reading protocol header Bugzilla: 1902237 RH-Acked-by: Danilo de Paula RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Marc-André Lureau While processing ARP/NCSI packets in 'arp_input' or 'ncsi_input' routines, ensure that pkt_len is large enough to accommodate the respective protocol headers, lest it should do an OOB access. Add check to avoid it. CVE-2020-29129 CVE-2020-29130 QEMU: slirp: out-of-bounds access while processing ARP/NCSI packets -> https://www.openwall.com/lists/oss-security/2020/11/27/1 Reported-by: Qiuhao Li Signed-off-by: Prasad J Pandit Message-Id: <20201126135706.273950-1-ppandit@redhat.com> Reviewed-by: Marc-André Lureau (cherry picked from libslirp commit 2e1dcbc0c2af64fcb17009eaf2ceedd81be2b27f) Signed-off-by: Jon Maloy Signed-off-by: Danilo C. L. de Paula --- slirp/src/ncsi.c | 4 ++++ slirp/src/slirp.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/slirp/src/ncsi.c b/slirp/src/ncsi.c index 6864b735db4..251c0d2bfbb 100644 --- a/slirp/src/ncsi.c +++ b/slirp/src/ncsi.c @@ -147,6 +147,10 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) uint32_t checksum; uint32_t *pchecksum; + if (pkt_len < ETH_HLEN + sizeof(struct ncsi_pkt_hdr)) { + return; /* packet too short */ + } + memset(ncsi_reply, 0, sizeof(ncsi_reply)); memset(reh->h_dest, 0xff, ETH_ALEN); diff --git a/slirp/src/slirp.c b/slirp/src/slirp.c index b0194cb32bb..86b0f52d923 100644 --- a/slirp/src/slirp.c +++ b/slirp/src/slirp.c @@ -700,6 +700,10 @@ static void arp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) return; } + if (pkt_len < ETH_HLEN + sizeof(struct slirp_arphdr)) { + return; /* packet too short */ + } + ar_op = ntohs(ah->ar_op); switch (ar_op) { case ARPOP_REQUEST: -- 2.27.0