From patchwork Mon Aug 31 13:04:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pengpeng Hou X-Patchwork-Id: 2295168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=KAEXWYIu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hYTjr3wLHz1xvS for ; Mon, 31 Aug 2026 23:05:04 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=SLcDh+hWwFwAkC2fEltBcuzvrYDBKLW8rmvwA3ivyQM=; b=KAEXWYIuz0lFQB ka3IVRbCCsGCgKsmfFJJjjYfBLm8zoSI5V5b7KBLUuOsmgUA80KwY7JIMZdiQhrbVgijzFo1EltBp cp+C2jkV0SSAo9VlWGfJhPt5MCWF84+utNfOPKCbYs5vhRmPFzIeLXwMCjgwiEoVUKQAGEkumHLh+ JSmBG1sOlizKRkOkN09E97ktTxyeODgZFPYp+8+veN9k4CSgTrHJsp5X0/5RSOcCcweKmbpS/M7nm NPHF902azpwQMnXu3a4lrZ9dZSuhg1MNk7UmhTmcq6zdN8+fDCrLmFdU655L0rS/2ljXdq4NvQghi +tDG76zKBqSDKqVjnCiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x11h1-00000009MJP-3Va6; Mon, 31 Aug 2026 13:04:55 +0000 Received: from smtp21.cstnet.cn ([159.226.251.21] helo=cstnet.cn) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x11gy-00000009MIQ-1SJi for opensbi@lists.infradead.org; Mon, 31 Aug 2026 13:04:55 +0000 Received: from localhost.localdomain (unknown [111.196.241.250]) by APP-01 (Coremail) with SMTP id qwCowABnOe3ve5VqgxbzBg--.20645S2; Mon, 31 Aug 2026 21:04:47 +0800 (CST) From: Pengpeng Hou To: opensbi@lists.infradead.org Cc: Pengpeng Hou , Rahul Pathak , Subrahmanya Lingappa , Anup Patel Subject: [PATCH] lib: utils/mailbox: Reject invalid RPMI queue indices Date: Mon, 31 Aug 2026 21:04:44 +0800 Message-ID: <20260831130444.53629-1-pengpeng@iscas.ac.cn> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 X-CM-TRANSID: qwCowABnOe3ve5VqgxbzBg--.20645S2 X-Coremail-Antispam: 1UD129KBjvJXoW7urW7GFykGF4xur13ZF18Krg_yoW8WFWrpF 4rG3s2q3y0qFW7Was8tw4Fq3Z7ur1kWry3J3s3G34rAwsIqr90vw17Ja4Yqry8XFyvyw4j v397u397C3WDXaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkm14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1I6r4UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkF7I0En4kS14v26r12 6r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI 0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y 0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxV WUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1l IxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUehL0UUUUU X-Originating-IP: [111.196.241.250] X-CM-SenderInfo: pshqw1xhqjqxpvfd2hldfou0/ X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260831_060452_750232_1F2BFB37 X-CRM114-Status: GOOD ( 10.37 ) X-Spam-Score: -4.2 (----) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The RPMI shared-memory helpers validate a queue index before using it to select queue_ctx_tbl, but the current comparison accepts queue_id equal to queue_count. Only entries 0 through queue_count - 1 are initialized from the device tree. Accepting queue_count can therefore use an uninitialized queue context when a protocol operation selects a queue omitted by [...] Content analysis details: (-4.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [159.226.251.21 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 DMARC_MISSING Missing DMARC policy X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The RPMI shared-memory helpers validate a queue index before using it to select queue_ctx_tbl, but the current comparison accepts queue_id equal to queue_count. Only entries 0 through queue_count - 1 are initialized from the device tree. Accepting queue_count can therefore use an uninitialized queue context when a protocol operation selects a queue omitted by the description. Reject queue_id greater than or equal to queue_count in both transfer directions. Fixes: 91f46fb47eef ("lib/utils: Add RPMI messaging protocol and shared memory transport support") Signed-off-by: Pengpeng Hou --- lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c b/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c index 521e0673..c9b2c6ef 100644 --- a/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c +++ b/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c @@ -313,7 +313,7 @@ static int smq_rx(struct rpmi_shmem_mbox_controller *mctl, int ret, rxretry = 0; struct smq_queue_ctx *qctx; - if (mctl->queue_count < queue_id) { + if (queue_id >= mctl->queue_count) { sbi_printf("%s: invalid queue_id or service_group_id\n", __func__); return SBI_EINVAL; @@ -348,7 +348,7 @@ static int smq_tx(struct rpmi_shmem_mbox_controller *mctl, int ret, txretry = 0; struct smq_queue_ctx *qctx; - if (mctl->queue_count < queue_id) { + if (queue_id >= mctl->queue_count) { sbi_printf("%s: invalid queue_id or service_group_id\n", __func__); return SBI_EINVAL;