From patchwork Thu Aug 1 12:27:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Carlos_L=C3=B3pez?= X-Patchwork-Id: 1967643 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=HznSpR3W; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Lcse8X10; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) 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 4WZT0H3Qdmz1yZv for ; Thu, 1 Aug 2024 22:33:35 +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=SDw4d3yMkm1pxkUGxYyOQ5hbH0L92g9HJtA/qXamHPo=; b=HznSpR3Wor7B8w p064bVKO+XJQf3YfeIPaKtzOMLok+dWBa+OrEcLAwxe4+phnu6hKop985JA3WsJDIh2ooyD3bU5Zd N6SG+wGFn7STsXvKLEdzdvVi1RqCa/hHMeoYt2PrXpR03RND8TXEnTikQ6o4RiCMMVTsfv6FUaEKg aMUDV15y8dJ613ld3LMlAeTJsxqJhnYPUrlojJ/sO2AkSo9Vv8oPJ3ViYUvEzmOs5Us5uyK9mAOis wUcGBS57zJ4CD2dv1CbT+luIdkxqn2dtUlsRHJLfzPeMhyV8UNgKTuh0hA3S3DjEOnNSDcFwGnzie aLHWdOsm2WT6JQmVY08Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZUzp-00000005DJa-1zdO; Thu, 01 Aug 2024 12:33:29 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZUub-00000005AaX-1Itj for opensbi@lists.infradead.org; Thu, 01 Aug 2024 12:28:07 +0000 Received: by mail-wm1-x341.google.com with SMTP id 5b1f17b1804b1-428e1915e18so4413955e9.1 for ; Thu, 01 Aug 2024 05:27:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722515278; x=1723120078; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lQQ/OGjX6w4nXgjowDWDKcXtBLmtCmVAh05t/I6a3Yw=; b=Lcse8X10YLhsqL3HwH91m2BlxbAnuQPg/LVFVIFTRAskFBueYWDefcENgX9p61wgDn 86pf8TilJwG9lpvt50KBX8XpWmh+WbydYB9gC03MWKOmmDKBwq8RNFUFIuYQhcX6RwwE kbcuPychx+0GoewIepRxSba6p8dh+IZE6ASFzTSLUOkKf/ewJY1dut8b53pwU7ITTMax mPtuMAa88fJe3l2X7QkSOlHkpXe/RujKlj963swevX6Bcqn+dZn38mcHEtHE467nUUaJ gnOY2UgR3hamPy2LtPuRLHDS62Tj43oRU6wfT742FCjaqOLgAEOgAnTEIjcpo7TjoMym /UUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722515278; x=1723120078; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lQQ/OGjX6w4nXgjowDWDKcXtBLmtCmVAh05t/I6a3Yw=; b=gcwJziCtfQ2Q8Vf7C9JX8TXY2uxts13ydBeu7V2+TGJ+C/gAQqa0Y2bioibLPwmrE+ JzApq1Vi4mPjAhlonEOuR/4t3Qe2xsAE/YQdJjSvIqmUoz7EZiH0M7FBy8Ltc9X72/aZ zFsEWogCYSQixz/pwuRNjWgLUqp6o2EX5tw1MBOayDH6cl7OxA+PYXQ7Y9PwFQsMkSSE HYqWG1GzFniz2dQBWxCJyrrhlfOptXp+8klY07op81PBGnmh7UW9V7bmJXd9dC0KpQVg 48TKhCjMC8Ci1kjr8059rz/CsBK7PZiRXZYepRi85sXt3OCJNhIIMqm4fFHQJoxIO20D Tmqg== X-Gm-Message-State: AOJu0YyezoWGvGBHbp0tRuBP6bn7J9DzVkVmxRWP58ZSyg6wK10rV+fL mc6XeNGnTL+284zrvMnPv3sLm5UNWackVKgBghD+n+4M8asOtsaTa0tli3JTPEw= X-Google-Smtp-Source: AGHT+IHg46VTTn5phWXvuSKsbIIKhqGX6Oevn2RLRcbezUGmyHAjyFQw5AsAAGNkyninmr71SMqFiw== X-Received: by 2002:a05:600c:4f43:b0:426:5c9b:dee6 with SMTP id 5b1f17b1804b1-428b030cc5emr16923465e9.26.1722515277995; Thu, 01 Aug 2024 05:27:57 -0700 (PDT) Received: from debian.myguest.virtualbox.org (182.red-79-153-116.dynamicip.rima-tde.net. [79.153.116.182]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-4282bb64b84sm55851865e9.32.2024.08.01.05.27.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 05:27:57 -0700 (PDT) From: =?utf-8?q?Carlos_L=C3=B3pez?= To: opensbi@lists.infradead.org Cc: =?utf-8?q?Carlos_L=C3=B3pez?= Subject: [PATCH] lib: sbi: dbtr: fix potential NULL pointer dereferences Date: Thu, 1 Aug 2024 14:27:42 +0200 Message-Id: <20240801122742.5001-1-carlos.lopezr4096@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240801_052805_475877_19448921 X-CRM114-Status: GOOD ( 12.28 ) X-Spam-Score: -1.8 (-) 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: In several dbtr functions, we first check that the dbtr trigger is not NULL and that its state is what we expect. However, it only makes sense to perform the second check if the dbtr trigger is not NU [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:341 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [carlos.lopezr4096(at)gmail.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [carlos.lopezr4096(at)gmail.com] 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 In several dbtr functions, we first check that the dbtr trigger is not NULL and that its state is what we expect. However, it only makes sense to perform the second check if the dbtr trigger is not NULL. Othwerwise we will dereference a NULL pointer. Thus, change the condition so that it shortcuts to the first check if necessary. Signed-off-by: Carlos López Reviewed-by: Anup Patel --- lib/sbi/sbi_dbtr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c index 6e2083e..27a8b91 100644 --- a/lib/sbi/sbi_dbtr.c +++ b/lib/sbi/sbi_dbtr.c @@ -357,7 +357,7 @@ static void dbtr_trigger_enable(struct sbi_dbtr_trigger *trig) unsigned long state; unsigned long tdata1; - if (!trig && !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED))) + if (!trig || !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED))) return; state = trig->state; @@ -403,7 +403,7 @@ static void dbtr_trigger_disable(struct sbi_dbtr_trigger *trig) { unsigned long tdata1; - if (!trig && !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED))) + if (!trig || !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED))) return; tdata1 = trig->tdata1; @@ -429,7 +429,7 @@ static void dbtr_trigger_disable(struct sbi_dbtr_trigger *trig) static void dbtr_trigger_clear(struct sbi_dbtr_trigger *trig) { - if (!trig && !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED))) + if (!trig || !(trig->state & RV_DBTR_BIT_MASK(TS, MAPPED))) return; csr_write(CSR_TSELECT, trig->index);