From patchwork Fri Feb 17 13:24:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Natalia Petrova X-Patchwork-Id: 58557 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp885916wrn; Fri, 17 Feb 2023 05:29:54 -0800 (PST) X-Google-Smtp-Source: AK7set+Twz6WOUo1aG2gmfynXZrBn1ciWTNcPLiFbF1f845y6P6r1V5geVwwfNlk8zE0tbABu/+W X-Received: by 2002:a17:907:3e29:b0:8b1:2614:edfe with SMTP id hp41-20020a1709073e2900b008b12614edfemr7046986ejc.9.1676640594683; Fri, 17 Feb 2023 05:29:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676640594; cv=none; d=google.com; s=arc-20160816; b=q3XlJcKQj5Tu7P33wR6hb5ZsUwHEaz7UlEfz+cGLlWO7BtGCsIEaD4zgOncyLyszBF PMygiCBNtgs7HwxGuYhwAlAu7MiHCZ96hznT63bWKjIFI7NICrjDsk/i7auYc31W5gt2 d1bYxoCqUTTUfagVOEg3ijXP1EH54C0sG4aggW5a6QeXiOzEoOGbSwNnq4xSwi/x3Duv Ny5b9DRRmxOwPGEBSERQaYq+5dwwq9mvoNJjfAPczUJuuJIhgzKO8Y/Te1020KSPA6DB z7Fqu4mV3RpD6t9Hit4nDSSrGugaTLUaJR5+JSka27isLNZpI3eL+QMUZswcuBt3BEwJ Y0bg== 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 :message-id:date:subject:cc:to:from; bh=KcJCqHrAxSvYJzhKOaibOldu5x3iVXS+o5HzT6tDqMo=; b=uLCJ9Y/b1Sir8CNrpzFYgNzw7ujla1HQe9ZOKMMV6/93A6uV8nWTCDsPYxj0wg2aVq iJoRlnG9sc7Tw/aBa0w3/mWXTX6fCJe95SOgpRoNy508n1sbUJaEwl20vyBdtnLxoBJQ l5BjDdN0KtHY8Mbre3hIReWRQdGdLIe2Dh0rouJJt5Bl9wWhByhV3z41JTwlPDfeJLnm R8rALbBB4fjx3BphOOvLIbeObl97hHADcuCuCXJjwmwm1k62//N7UNcMiUwjXoPy7Hh0 UY2GxhKSS0+xwmERZbOYTVDrgCB90rey2JcvK63WLVBaodPJ7Tg3mQpgJ7mUKu1WmE5H Wt0w== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ex20-20020a170907955400b008b143bc84ebsi4076064ejc.380.2023.02.17.05.29.31; Fri, 17 Feb 2023 05:29:54 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229789AbjBQNYl (ORCPT + 99 others); Fri, 17 Feb 2023 08:24:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjBQNYk (ORCPT ); Fri, 17 Feb 2023 08:24:40 -0500 Received: from exchange.fintech.ru (e10edge.fintech.ru [195.54.195.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35C2267452; Fri, 17 Feb 2023 05:24:36 -0800 (PST) Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.159) with Microsoft SMTP Server (TLS) id 14.3.498.0; Fri, 17 Feb 2023 16:24:34 +0300 Received: from KANASHIN1.fintech.ru (10.0.253.125) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Fri, 17 Feb 2023 16:24:34 +0300 From: Natalia Petrova To: Andreas Noever CC: Natalia Petrova , Michael Jamet , Mika Westerberg , Yehezkel Bernat , , , Subject: [PATCH] thunderbolt_tb: add check for return value of 'tb_switch_find_port' Date: Fri, 17 Feb 2023 16:24:32 +0300 Message-ID: <20230217132432.487106-1-n.petrova@fintech.ru> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.0.253.125] X-ClientProxiedBy: Ex16-01.fintech.ru (10.0.10.18) To Ex16-01.fintech.ru (10.0.10.18) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758085088075307954?= X-GMAIL-MSGID: =?utf-8?q?1758085088075307954?= Return value of 'tb_switch_find_port' has to be checked to avoid null pointer dereferences in functions tb_tunnel_alloc_dma() and tb_port_info(). Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 386e5e29d81c ("thunderbolt: Make tb_find_port() available to other files") Signed-off-by: Natalia Petrova --- drivers/thunderbolt/tb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c index 9853f6c7e81d..5d6cded68d46 100644 --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -1156,6 +1156,8 @@ static int tb_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, sw = tb_to_switch(xd->dev.parent); dst_port = tb_port_at(xd->route, sw); nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI); + if (!nhi_port) + return -EIO; mutex_lock(&tb->lock); tunnel = tb_tunnel_alloc_dma(tb, nhi_port, dst_port, transmit_path,