Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp583493iog; Mon, 13 Jun 2022 08:34:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweQpT/8mleZzpVDbaE6eXhqZMDyIJtRxETzLBfE78PXYvvN+t/ugd5WZgFJuOaxmDTgCuH X-Received: by 2002:a17:90b:304:b0:1e3:4489:193c with SMTP id ay4-20020a17090b030400b001e34489193cmr16461741pjb.78.1655134485122; Mon, 13 Jun 2022 08:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134485; cv=none; d=google.com; s=arc-20160816; b=YzFbSkOaUFXBUys9riDRAV6pqSQy81HpNeG2MoHbb6NpAhqMok1lfww2OHAalVRftr Ag78/XYQFHK+QEgMNXL1XnGonoRzhNqfxvXWV1eDTynVgPhHUiI4JDem1J3ndXmqlmY+ 9T/Y7aJUC1v6gtlsAhKNmkGUXXeR+1WyKFYZn7ew+3A7Xh4SmVC0uWgefPo9NrDgv8ps PvLQxMkgTFG8fxyCsyu2q3zLCztvANKDTA6hO3Ne8UtOrNTxtIitB4xuqxb1jVnckUjM 2o0QHOH5nHw3UR+sb+5Off4HWtTZhqpzVzhbI9ELQA4yRWGajMOpxU5ptsxHvggRzjd1 mKUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=emyV5qc5NZJimJUcXZaUtu+1NxfST5JwuSEnjDsmJlI=; b=OHDZMigROFFpB6qNJ/F1nRm8DfGKejIuyfFheTX8z68dKSbmDfodenNOa/EMhZSgnO vtognpbhEUFSiI7c7cD5w9FrL6Nm17SWH1Dao1XI+TiPPtbyOcVXIEd4leqrgZ5U8kD2 p8m3kTqgj+MK7RmUhVdOq0ncipefrRHNDqqsMWXplLVMMt45QwTzpL8kv6MzFAvGVzR5 YayTCPAB6+zeXOV2AWFtI1Pmywp8G/IAz6/MWcL6Xd7MotV+IIWsVm+1Io5rs4Yy3Lon +E5cY7/MHXncB3dFQHy731f4LyRca72ocEVfvXoTODCIYjQWhKgaVbdMjsaPD3LqTNLf VUnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zk1YFKJG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b19-20020a637153000000b003fc5fe35f9asi9625612pgn.415.2022.06.13.08.34.32; Mon, 13 Jun 2022 08:34:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zk1YFKJG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240295AbiFMNA1 (ORCPT + 99 others); Mon, 13 Jun 2022 09:00:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358055AbiFMMzB (ORCPT ); Mon, 13 Jun 2022 08:55:01 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7957635865; Mon, 13 Jun 2022 04:14:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 319C5B80EA8; Mon, 13 Jun 2022 11:14:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B0F0C34114; Mon, 13 Jun 2022 11:14:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655118845; bh=bqxwt3xMXRrlP2ECcIaUOns90969ytvB6D4J7Y1DLds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zk1YFKJGo44qqTPe0Ixs8MTvKwM1LeOdoYIOsH2DcTtmLK0vms2UPblw6g37VyARh +f0KV+pxZMzgzI3wQ5h0r9jyhjOEdgFWgH0DA2QCwwPYKCuSrM25cG34doJkltCxgt LN3Yjx5NZYGaXQav7wRG9Lp0IKsjh07FEP2rCSDE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaomeng Tong , Sasha Levin Subject: [PATCH 5.15 022/247] misc: fastrpc: fix an incorrect NULL check on list iterator Date: Mon, 13 Jun 2022 12:08:44 +0200 Message-Id: <20220613094923.605006234@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaomeng Tong [ Upstream commit 5ac11fe03a0a83042d1a040dbce4fa2fb5521e23 ] The bug is here: if (!buf) { The list iterator value 'buf' will *always* be set and non-NULL by list_for_each_entry(), so it is incorrect to assume that the iterator value will be NULL if the list is empty (in this case, the check 'if (!buf) {' will always be false and never exit expectly). To fix the bug, use a new variable 'iter' as the list iterator, while use the original variable 'buf' as a dedicated pointer to point to the found element. Fixes: 2419e55e532de ("misc: fastrpc: add mmap/unmap support") Signed-off-by: Xiaomeng Tong Link: https://lore.kernel.org/r/20220327062202.5720-1-xiam0nd.tong@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/fastrpc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 86d8fb8c0148..c7134d2cf69a 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1351,17 +1351,18 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_req_munmap *req) { struct fastrpc_invoke_args args[1] = { [0] = { 0 } }; - struct fastrpc_buf *buf, *b; + struct fastrpc_buf *buf = NULL, *iter, *b; struct fastrpc_munmap_req_msg req_msg; struct device *dev = fl->sctx->dev; int err; u32 sc; spin_lock(&fl->lock); - list_for_each_entry_safe(buf, b, &fl->mmaps, node) { - if ((buf->raddr == req->vaddrout) && (buf->size == req->size)) + list_for_each_entry_safe(iter, b, &fl->mmaps, node) { + if ((iter->raddr == req->vaddrout) && (iter->size == req->size)) { + buf = iter; break; - buf = NULL; + } } spin_unlock(&fl->lock); -- 2.35.1