From patchwork Sat Mar 15 09:14:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 873866 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp1104400wrq; Sat, 15 Mar 2025 02:15:40 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWkF0TxKkI6bSotQL8qlZTTSRe1uc1/s+AKlV4kqV/+9zMTP1v21U8SToGESwACBwqt3OzyDw==@linaro.org X-Google-Smtp-Source: AGHT+IFwI6Bxk1YBLKeBnFfwQ+EnsO9Kx4dA3EhWRyfJZIxRB2Qp8hq2/t2hLmqbfq++/iaYIHWZ X-Received: by 2002:a05:6214:2a48:b0:6e8:fa33:2962 with SMTP id 6a1803df08f44-6eaea9e44b4mr76601406d6.10.1742030139838; Sat, 15 Mar 2025 02:15:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742030139; cv=none; d=google.com; s=arc-20240605; b=XjPcVyGn+g6/1GLNbnWEFvKaiyzJV7QdbIurEs7L3/6YrxP3lNWx3s0Les/PoGVHUS bUKw9f847GFVTrIDdljkIjoiyQabrjwS+D3H3sceBG5mBnQ3EksTayUfof2rxfiuPERf jWlcv1havpV8AAGtZvptm5ksUs7atUKDnv4fD+lum2zoiwTwysYDN90WTkIxoSWvUS/9 S4fKbSqItc7LYKmMoyzWwWzfbltbCgI0aIYzRw9OcHyNB0JL+9MRNR9CPI+BOB3SWehw 6NTQZ//kbHfvBR+0LPilbfYoDkKsxAU0ha297WugXWyRU50vkVJ8OP8/cJ3jDiD9ersQ OYQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=jfYVvxRSHPpKYFtAWIVzZJDdvJfQqo5qz4AMq7Yi4xo=; fh=He0A/96iGS/hdBTIvTFKPoE7yByjlEm52ubAJxr7bqo=; b=Q87G12+bvzpvnh3/JqHhz7vZqsQHm8uP2Zo0uFF0qqeAz4dWsUXrEXjO8aj5CLeNOF L/VN+6euKA76xqg9IsUs2PjY/I990RjVxf+z79P6h7ghWq9u4NvkYgZhrs8JDPdisXYy JXqzS1rzPDWswDdnsSS8yhPZZwjiwh6NYGbQSeHL5voPpp5/lDR1a98I5qCY2RwHmtau FIs4HmrZ+zb6g802TqK64U7+VIsnTGnKYCfGsenmOlCPUgZkbGO047EgcIWsq7xQkap/ OUcEew2AX6KfhpMe6VVRt65jsB3a1JQPhePEteZ0GB+aIl3p7eAxlTcXjDj8VXLolBEY 01Hg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6eade33f708si53261416d6.170.2025.03.15.02.15.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 15 Mar 2025 02:15:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ttNbg-0002eP-BZ; Sat, 15 Mar 2025 05:15:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ttNba-0002cH-3z; Sat, 15 Mar 2025 05:14:56 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ttNbW-0007k1-9j; Sat, 15 Mar 2025 05:14:53 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id AA655FFBB4; Sat, 15 Mar 2025 12:13:45 +0300 (MSK) Received: from gandalf.tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with ESMTP id B2DD31CAD4D; Sat, 15 Mar 2025 12:14:39 +0300 (MSK) Received: by gandalf.tls.msk.ru (Postfix, from userid 1000) id 99E7155A30; Sat, 15 Mar 2025 12:14:39 +0300 (MSK) From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Tokarev Subject: [Stable-7.2.17 03/27] hw/net/smc91c111: Ignore attempt to pop from empty RX fifo Date: Sat, 15 Mar 2025 12:14:14 +0300 Message-Id: <20250315091439.657371-3-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Peter Maydell The SMC91C111 includes an MMU Command register which permits the guest to remove entries from the RX FIFO. The datasheet does not specify what happens if the guest tries to do this when the FIFO is already empty; there are no status registers containing error bits which might be applicable. Currently we don't guard at all against pop of an empty RX FIFO, with the result that we allow the guest to drive the rx_fifo_len index to negative values, which will cause smc91c111_receive() to write to the rx_fifo[] array out of bounds when we receive the next packet. Instead ignore attempts to pop an empty RX FIFO. Cc: qemu-stable@nongnu.org Fixes: 80337b66a8e7 ("NIC emulation for qemu arm-softmmu") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2780 Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20250207151157.3151776-1-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daudé (cherry picked from commit 937df81af6757638a7f1908747560dd342947213) Signed-off-by: Michael Tokarev diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c index 4eda971ef3..6ce610cb23 100644 --- a/hw/net/smc91c111.c +++ b/hw/net/smc91c111.c @@ -183,6 +183,15 @@ static void smc91c111_pop_rx_fifo(smc91c111_state *s) { int i; + if (s->rx_fifo_len == 0) { + /* + * The datasheet doesn't document what the behaviour is if the + * guest tries to pop an empty RX FIFO, and there's no obvious + * error status register to report it. Just ignore the attempt. + */ + return; + } + s->rx_fifo_len--; if (s->rx_fifo_len) { for (i = 0; i < s->rx_fifo_len; i++)