From patchwork Sat Mar 15 07:42:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 873852 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp1080416wrq; Sat, 15 Mar 2025 00:44:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUYoZeEaHf3CatgVZL86eFPMKj0a1X3lN46oY5qpju0DBnxjfuU9JF7ZplHqKhMYwpFewXs4A==@linaro.org X-Google-Smtp-Source: AGHT+IHRGeKVgprg6iZEhdG9YjvCU98jWdMQV7LYS9zRMtMNpbM0Kdlprc8+D8Gdx2EFT8TryOMO X-Received: by 2002:a05:620a:1996:b0:7c5:3b3b:c9d8 with SMTP id af79cd13be357-7c57c8c0344mr771547585a.45.1742024657814; Sat, 15 Mar 2025 00:44:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742024657; cv=none; d=google.com; s=arc-20240605; b=HPTFLZoxaKDSe1yBs2b5qdh+RBhjx0keLnWCoWygAadrNQEF3mwlsuuh6Nu9lVKGYq houFue6bQcHAI/NJH5iGYnxNkkOl7q0xOP8x6HIV+bnO0U37Gw71eJgVlDECLXY/yZge gWTOEvJ0N9VfVVhzE9ztKZpOUMA8VmzQp1/56ux/aICgUtznIBheKRsz0sCi6D/jjlyz bTcY8fbOui78Y2nG2sJJJAty/HsGdj8c/42WJuq8hrVpfKUz4LtZnXXEzdWB4Ya5iJaB 6HiNkMwmU1PXBAJxV1dZwpV/Uc2VoiD27DYEKygEutg5mKdfPmm6zhD+M3qtdJVUvOK6 oqGw== 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=SBBJHKlyWUZGR2ogDkvIQPGBHWn7hWdTIUUIEfJIkr8=; fh=He0A/96iGS/hdBTIvTFKPoE7yByjlEm52ubAJxr7bqo=; b=LHCfXUsIE6EYqpwY7CqanHPXsGwAVEHxnUVduhzgv5LEhV/w8IFqRGqmMtcJk3O3oW JQr9qodtsDIDQdSfu6F1ZPjVuCQsRn2BwHLXrNR7olgipxFcd9ZOYEvO1NtwVXycE5oW d4tCpB7430l9TqRCpyE4YEDIQwnW8JhOabDRXSSF3ZwdqKp+2ajldAX4RSLA/FdK0FWB xyXeGEmn/6ZPOwU4D+14bmhOY2Hfu0pfqIZW3/izPH1/tdlffJjbGwhdtAQjBCGO8RMT hI5C3sHTxJXTKf8/ESn8V9zvMN6I8Flve110l710X4bUAAPGFQWkL9dL3TOJ3FkNSEa+ oFLQ==; 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 af79cd13be357-7c573b72f8esi588645685a.114.2025.03.15.00.44.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 15 Mar 2025 00:44:17 -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 1ttMAm-0001yO-5T; Sat, 15 Mar 2025 03:43:08 -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 1ttMAi-0001ws-Cf; Sat, 15 Mar 2025 03:43:04 -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 1ttMAg-0004mD-JJ; Sat, 15 Mar 2025 03:43:04 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 92CB3FFAF9; Sat, 15 Mar 2025 10:41:55 +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 816AB1CACC3; Sat, 15 Mar 2025 10:42:49 +0300 (MSK) Received: by gandalf.tls.msk.ru (Postfix, from userid 1000) id 649B1559DE; Sat, 15 Mar 2025 10:42:49 +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-8.2.10 05/42] hw/net/smc91c111: Ignore attempt to pop from empty RX fifo Date: Sat, 15 Mar 2025 10:42:07 +0300 Message-Id: <20250315074249.634718-5-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 876a78456a..dcf6e5117f 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++)