Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2283201iof; Wed, 8 Jun 2022 01:22:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysIPRvlylL2I1psemVO8TkQa7oeonYphdRweccSaH1JnLoRdE9Xe/Iu8yBGZCViT4bA9S0 X-Received: by 2002:a17:90a:5ae1:b0:1db:d0a4:30a4 with SMTP id n88-20020a17090a5ae100b001dbd0a430a4mr36569646pji.128.1654676552765; Wed, 08 Jun 2022 01:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654676552; cv=none; d=google.com; s=arc-20160816; b=TzGQHS/ckJrn5LP26xSrpqubANgFXmDAJBsuXop0CCbUG4tUU78wf9c5PyqcKHwq6C awucUjh4rUxF6NygNz/KlnwW11Mr2xZrOSwEZesA4eG2YP2Mnk0X5lpKNgMw1Uda3TjB P64/eKou1j2L4LfPY5zaM/xQhEfgMKJ06jHTD4CVhLuE5HBgfXigI2UjWlbkYORNu7NY mh/oO4F8D58QrE9p8FjTwev4W7Wv/90TFIl3nCf/BBtLAYNk2iSi5Pl9ay532yYGCm2E myxGpbbcnS3UoSZO6rbTLxAHLWjJ2/DyA8yOkFRTDar1M3Zw5cfHSdVYddUdk8fwDe3C vhsg== 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=ABVu5hiWC1gsaWbpcUH2O731SIl9bYK8DnnobqCTwEQ=; b=mqc6aoy2HpJj8tO/jXtCgbR34QLibNVoPueiiBeyrm6BP3R4r6VqDV4bvNmT8FxpUv nn4BdiVkI3RD28GRHjLTf2um6X9Lj0HwIf4qh2K4wS2nIsKiCzRVJ7Fwj7Eqmx2jrp25 Et7fymnK5xi6iSycxFJB2L19uIvtm5nGDtX7Fw0ShEpr4Q0ef7pPpCZoHwsMQ1Y+qteC KyDDSfHwxuhRC0U4rYKg59awGTwi3e7PS3dm9D/7+KMJTNR488xz0XvenIxVKDeqa4E+ 1ALDa8QE4poDSBSJUJs4C15gFHPUpeV28LLmzRcq9vF6gHocealGVsCtOZcZ0SWK2IJT TGBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bCGgJCXH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c12-20020a655a8c000000b003fbbddcde14si26153186pgt.492.2022.06.08.01.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 01:22:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bCGgJCXH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A09E03B4060; Wed, 8 Jun 2022 00:52:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233953AbiFHDRm (ORCPT + 99 others); Tue, 7 Jun 2022 23:17:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346406AbiFHDOd (ORCPT ); Tue, 7 Jun 2022 23:14:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00C1519EC05; Tue, 7 Jun 2022 12:26:10 -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 A3550B823CC; Tue, 7 Jun 2022 19:26:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D833C385A5; Tue, 7 Jun 2022 19:26:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629968; bh=ydX+2CKF6CXsKEyIp/NMR38F13oGuyKzNtRL6g2GNiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bCGgJCXHl5Sxqzkq98hUAN/g42XDLoerZFgAPdI2Ke9TMdjSwbXHwJ8qHE8CEQXSR ffJ3NW1aUUl5j1ItSaWZh00P8+u4QbgTSQ0Rr7YniAyZoMKbALQFKSYXOT/K2sI3Cj rP64Of8X2J1InIFsSHF4WzZmHjCuMjx7kRzj+1nY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Jablonsky , Srinivas Kandagatla Subject: [PATCH 5.18 853/879] misc: fastrpc: fix list iterator in fastrpc_req_mem_unmap_impl Date: Tue, 7 Jun 2022 19:06:11 +0200 Message-Id: <20220607165027.614890950@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: Srinivas Kandagatla commit c5c07c5958cf0c9af6e76813e6de15d42ee49822 upstream. This is another instance of incorrect use of list iterator and checking it for NULL. The list iterator value 'map' 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 (!map) {' will always be false and never exit as expected). To fix the bug, use a new variable 'iter' as the list iterator, while use the original variable 'map' as a dedicated pointer to point to the found element. Without this patch, Kernel crashes with below trace: Unable to handle kernel access to user memory outside uaccess routines at virtual address 0000ffff7fb03750 ... Call trace: fastrpc_map_create+0x70/0x290 [fastrpc] fastrpc_req_mem_map+0xf0/0x2dc [fastrpc] fastrpc_device_ioctl+0x138/0xc60 [fastrpc] __arm64_sys_ioctl+0xa8/0xec invoke_syscall+0x48/0x114 el0_svc_common.constprop.0+0xd4/0xfc do_el0_svc+0x28/0x90 el0_svc+0x3c/0x130 el0t_64_sync_handler+0xa4/0x130 el0t_64_sync+0x18c/0x190 Code: 14000016 f94000a5 eb05029f 54000260 (b94018a6) ---[ end trace 0000000000000000 ]--- Fixes: 5c1b97c7d7b7 ("misc: fastrpc: add support for FASTRPC_IOCTL_MEM_MAP/UNMAP") Cc: stable@vger.kernel.org Reported-by: Jan Jablonsky Signed-off-by: Srinivas Kandagatla Link: https://lore.kernel.org/r/20220518152353.13058-1-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman --- drivers/misc/fastrpc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1747,17 +1747,18 @@ err_invoke: static int fastrpc_req_mem_unmap_impl(struct fastrpc_user *fl, struct fastrpc_mem_unmap *req) { struct fastrpc_invoke_args args[1] = { [0] = { 0 } }; - struct fastrpc_map *map = NULL, *m; + struct fastrpc_map *map = NULL, *iter, *m; struct fastrpc_mem_unmap_req_msg req_msg = { 0 }; int err = 0; u32 sc; struct device *dev = fl->sctx->dev; spin_lock(&fl->lock); - list_for_each_entry_safe(map, m, &fl->maps, node) { - if ((req->fd < 0 || map->fd == req->fd) && (map->raddr == req->vaddr)) + list_for_each_entry_safe(iter, m, &fl->maps, node) { + if ((req->fd < 0 || iter->fd == req->fd) && (iter->raddr == req->vaddr)) { + map = iter; break; - map = NULL; + } } spin_unlock(&fl->lock);