Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp260640pxb; Fri, 15 Oct 2021 05:09:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxm4Us96BqYRks9hFGlZoe0SjZe6sAX6LyLVe+NWhIoWfjPWrBPK6GjQQyTaV+b/aoDOA7 X-Received: by 2002:a17:906:789:: with SMTP id l9mr6434600ejc.61.1634299745964; Fri, 15 Oct 2021 05:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634299745; cv=none; d=google.com; s=arc-20160816; b=0wJoynVNz+8DI4AXd2txkoMbn20fhzl9Yy6H9WBSnF+3/PLplw31JF4Y5Vwh0jCyqs 2sWSMI9YGiqru4Trb4jqb8X5+Uc6DieoPA3HbwN8/EM7S+2JtwLx+Xpf7XkCDb1V6ZOI CIfkcjx+fiKQFVJYvnJkfrokbPCAPYSSG63+iQgBBJ0R1FJSczKsUnosggsuE89dhak3 QNySMU3Lpq2ckj12YmHY4NIe5OsscgsocGSKb0CdGulivW8i+oA20jk69bZ1BGhRUKqn yW1Wzh2pQyTld6646G8q/Hz66ylcJ2qSKn0oMkUMeictfwkPQSROZei1c6KayZtX1W/w 3K4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=RVpuGq9osjd7jvGWo4lIxd4Mr3DYcBLkEIpQ9siO3nw=; b=uwPNEBZAOmXzgwSF3eOfayPoUXwhtKKh/nLCYBTXt0M9BOwvuWJXeY6+PaOu+1ioi+ u0YmlU41n+aWu1iv4A9X027DnHBRjEN7LULSmt3jMQPlFLnOrAp0FPYvnyTC7In77buU N+zd3GwQVT0DiOjjdmr5B3fFadqjhuB6I1e1nSNp1VgGg/VKm89+GJ3hiUKFVQueTRos 03kwQe1VrE0RKrfDXaQLz7wQVcBigwucq9H0ED+4TgHktKpQ6YDYJ0QfIxNi+4hu9uSu MbDg9uT1FJDzOclHN87w3mhiJ3fVZ/PMIrl2KQvzv6nCKGKF1pwZqbdXfr7zpnqvkjQX SRwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y122mcwL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w2si7784325ede.421.2021.10.15.05.08.42; Fri, 15 Oct 2021 05:09:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y122mcwL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235324AbhJOFBb (ORCPT + 99 others); Fri, 15 Oct 2021 01:01:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:35438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235321AbhJOFBa (ORCPT ); Fri, 15 Oct 2021 01:01:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 61FCB611BD; Fri, 15 Oct 2021 04:59:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634273960; bh=/uoHz+FQ9emMCfOnNYpHnuX4+14/9z8ccvDRKSLVoP0=; h=Date:From:To:Cc:Subject:From; b=Y122mcwLoD/b2wScp+5PQopFaEb6gR0jljnYfdJ8WTuF1/akfspve+cPzp1y3YShC v4gV6akOfvRasvStU+V2JIX/cgiXQE7b10eR4iLwC4EgrMeTULlG95nltbW6U4atQm aov3vHuN9LLbxQFeXiW4Qu1k1zRGGlD07PpvxB2KzrLLn5jy70kPO4Zrs9bOexCQKi ZYg06OMNThgTC4UcTqkCEvveHGrk92/2kAdEhVkh74kd4hjIIFPZUypny/G2aZ4rl7 fQ/8rhrKbzgLPrKINnYy1i4aEUPeRzIYq79/k8QmFvJ6etlS00hdAJWF1LLLKJa2PY lFBD8l1U7shqQ== Date: Fri, 15 Oct 2021 00:03:45 -0500 From: "Gustavo A. R. Silva" To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Nicholas Piggin , Haren Myneni Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] powerpc/vas: Fix potential NULL pointer dereference Message-ID: <20211015050345.GA1161918@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (!ptr && !ptr->foo) strikes again. :) The expression (!ptr && !ptr->foo) is bogus and in case ptr is NULL, it leads to a NULL pointer dereference: ptr->foo. Fix this by converting && to || This issue was detected with the help of Coccinelle, and audited and fixed manually. Fixes: 1a0d0d5ed5e3 ("powerpc/vas: Add platform specific user window operations") Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva --- arch/powerpc/platforms/book3s/vas-api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/platforms/book3s/vas-api.c b/arch/powerpc/platforms/book3s/vas-api.c index 30172e52e16b..4d82c92ddd52 100644 --- a/arch/powerpc/platforms/book3s/vas-api.c +++ b/arch/powerpc/platforms/book3s/vas-api.c @@ -303,7 +303,7 @@ static int coproc_ioc_tx_win_open(struct file *fp, unsigned long arg) return -EINVAL; } - if (!cp_inst->coproc->vops && !cp_inst->coproc->vops->open_win) { + if (!cp_inst->coproc->vops || !cp_inst->coproc->vops->open_win) { pr_err("VAS API is not registered\n"); return -EACCES; } @@ -373,7 +373,7 @@ static int coproc_mmap(struct file *fp, struct vm_area_struct *vma) return -EINVAL; } - if (!cp_inst->coproc->vops && !cp_inst->coproc->vops->paste_addr) { + if (!cp_inst->coproc->vops || !cp_inst->coproc->vops->paste_addr) { pr_err("%s(): VAS API is not registered\n", __func__); return -EACCES; } -- 2.27.0