Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2941929rwb; Mon, 5 Sep 2022 04:10:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR79xCpycTFbJVGfZNUqdcbUxbb9SOtZr/5cZ9ifpN4rfn8DWYONvhVsy/9vz+Gr9LnJ8NOK X-Received: by 2002:a17:907:75c1:b0:72f:248d:5259 with SMTP id jl1-20020a17090775c100b0072f248d5259mr36296134ejc.227.1662376217348; Mon, 05 Sep 2022 04:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662376217; cv=none; d=google.com; s=arc-20160816; b=XvMg4iYlbSdPmjneHAhw8G7kYaz7hqHdxoq8MyMduGJdEmNdstZyEaHKT41JmR53cq BoRnidg/io4Y2wJIcTDaeDC+q8vDAxZGUT+o8aH2hypwzcRcbjO6zpv8dNiY0/U9hTDh ehUjP1s5NLZDhi1Z9m16Svv01DrJiYcdDaf8U3RgRe2NOVawlQxGtSKfBWs8mKdzd1NQ 1rAsTsKVYv6axmpyZ8EHRjAKHHl6WjzUbXT/wqccJ3IKYY/zoHPPyMCKTRUMYVrhgbzi q2+elrvRSlQGm3BICqCbFJPqq3L3ygMcWIMMyX6So1n6T1lJy6uM31jHN0vtqBLMp9Jf bfQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=0Hj1wEAOpkUv6/TSu6XuMoeXP2L0omD8v1o886j2aDg=; b=cr1ifAmGc8BTeBacy0+q+b1lJbJid3atGBU7oF7O4QcTz9Ztl9+6E97dgAmcJuZKqH fmEyQbpbcrWPcQW+RenVXdF5csoOTJnsz7/XW+oKP3pcfdETN2nWdPGT2LfXcAvYVi3w OrNfjVpKAYtVbjck7RxMkAAxa6wwOTYbkz+MuEFjaPanMis+O4IvAyDh15/FxKjyEQVL 5VWvz0I0DgaYhEd6WGesyK2EHYoUGpeI4/yqeOoKkiGmagvqoSo7vTtENIUlBnTZ89Ar Hr9w5BKPkPMPequpUaeID4DiWRlJFhWjflm6YIDxkSu5Rly6g9Z69mT65hNL/ML4zBkX Q8eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mQGKsPu4; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s11-20020a170906c30b00b0073d607b475dsi6512910ejz.168.2022.09.05.04.09.50; Mon, 05 Sep 2022 04:10:17 -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=@intel.com header.s=Intel header.b=mQGKsPu4; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236805AbiIEKTG (ORCPT + 99 others); Mon, 5 Sep 2022 06:19:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236413AbiIEKSN (ORCPT ); Mon, 5 Sep 2022 06:18:13 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91CD55464C; Mon, 5 Sep 2022 03:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662373044; x=1693909044; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=PbFMApXZgw+38bgGm8dKdd9ii/xxRNRjkKs3anjHN+g=; b=mQGKsPu4pnN6i1n5bwLFpr4dRZjSusptueuU7pIP5jf+pM1ZIS0pWMyc P9em7OEOrjMsOq9xXdOQnO/WEckpGQrBbPrdBKUyev00obq5+xvzq52H1 y7CKoJRjfcaPoNT4HKxkGCFfRmaEz9RMmxWpoGOFlPVJLSf1zLrkDQ10d kaxPOTetcHQpc/oo0X1BkMwbbFLsh5DGzVxVOmY6SOKzSn9R4JrGD68fq 9bBB9EZ7r8tIGwO3LASM27MA/sa9Jjej7N3tV8EPC9gFDmabOlj4X48m/ ecLoCUcriePf7f+/GN7yyX2g5DMeR+SLww0Pfj0YXAlLz+wjAeFZonAQu g==; X-IronPort-AV: E=McAfee;i="6500,9779,10460"; a="358073048" X-IronPort-AV: E=Sophos;i="5.93,290,1654585200"; d="scan'208";a="358073048" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 03:17:09 -0700 X-IronPort-AV: E=Sophos;i="5.93,291,1654585200"; d="scan'208";a="675231205" Received: from lpontegg-mobl.ger.corp.intel.com ([10.249.45.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 03:16:51 -0700 Date: Mon, 5 Sep 2022 13:16:46 +0300 (EEST) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Li Zhong cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org Subject: Re: [PATCH v3] drivers/tty/serial: check the return value of uart_port_check() In-Reply-To: <20220904004524.2281227-1-floridsleeves@gmail.com> Message-ID: References: <20220904004524.2281227-1-floridsleeves@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 On Sat, 3 Sep 2022, Li Zhong wrote: > uart_port_check() will return NULL pointer when state->uart_port is > NULL. Check the return value before dereference it to avoid > null-pointer-dereference error > because the locking does not guarantee the return value is not NULL. Please include also the answer to the "Why it doesn't guarantee?" question. In addition, it's expected you'll keep the people who have expressed interest in your patch among the receipients for any new version you send out. Thank you. -- i. > Here we do not need unlock in the error > handling because the mutex_unlock() is called in callers. > > Signed-off-by: Li Zhong > --- > > v3: Add the reason why we need to check the NULL value in the commit > message. The bug is detected by static analysis. > > --- > drivers/tty/serial/serial_core.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c > index 12c87cd201a7..760e177166cf 100644 > --- a/drivers/tty/serial/serial_core.c > +++ b/drivers/tty/serial/serial_core.c > @@ -194,6 +194,9 @@ static int uart_port_startup(struct tty_struct *tty, struct uart_state *state, > unsigned long page; > int retval = 0; > > + if (!uport) > + return -EIO; > + > if (uport->type == PORT_UNKNOWN) > return 1; > > @@ -498,6 +501,8 @@ static void uart_change_speed(struct tty_struct *tty, struct uart_state *state, > struct ktermios *termios; > int hw_stopped; > > + if (!uport) > + return; > /* > * If we have no tty, termios, or the port does not exist, > * then we can't set the parameters for this port. > @@ -1045,6 +1050,8 @@ static int uart_get_lsr_info(struct tty_struct *tty, > struct uart_port *uport = uart_port_check(state); > unsigned int result; > > + if (!uport) > + return -EIO; > result = uport->ops->tx_empty(uport); > > /* >