Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2237535rwl; Fri, 6 Jan 2023 03:55:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXtIIkl4TZjLi8q6NnTmeFUOgJEVFwuTJ3tqThnmIAA4/eMcc1injZ7ItLlZxVoRfuWN64ly X-Received: by 2002:a17:90b:b0c:b0:223:9e00:85bd with SMTP id bf12-20020a17090b0b0c00b002239e0085bdmr58058496pjb.40.1673006152662; Fri, 06 Jan 2023 03:55:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673006152; cv=none; d=google.com; s=arc-20160816; b=MbZJdUOyvUqcFaxDNKzy8EkLhax66UDaj3WWTbqTgkhybbwjwiZ0WUBRViLx3CYG1R AOOJQPoMJ+QxhyqXgfddpsKAhaUnh38f8dfH9uXN+giMiiyMb61jX+FXehqsvPaBmmKX t98OdpkpeKXaMmuLgOmseLy1e1kmr8lnhBVPVoP58G/FtEsv/IVKoeLsK5M5w6urGxis Fp0tkYgvci4HZ2ACADRa0aQB2VUpdqsNL273TpigHa5We9acK2Vm4RlrxfTLzEIp1hkJ 7WGKcShhsPg72lH1twwz4eoHKOyEcF967fWvbg592YtAdTKbarGtxtF45FVg+8idZD5u S8kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=uhIHBf7ySo1e4+280zbCgWIIfzgfwVln269wVcJ7yJM=; b=tbF6BNJ/3lBxFYE45YIH+nL8KfDFOY5C3dZAB/3lYoWN6OaLxLUdH7wbZHlyBN8Pmm mprTlnEaP/6ytSF0QWDn8hE6wmKQE0T1ENvSebGQBmIW4tJU3nBXSc6Deq5gsp2NvCYm MyGYZNlnSr70A585PEw72AwQ540B2545r9iK/JmQ+pX4JRGxgqp91GjAiCuQc0xXq4mS q9/rb0w3vNW0EAqde+p7Qi8hSkpSC4rGw1CIDWaFwSiN4wDRCeUClNpLypfPCgITAlZ5 T7Ff2mCrbBJZJfEsLu/6qKyL2GX0LTCC+r4+QqYiSvL6f9kiluWAIayoUNgaXOVVYUlH WM7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HAPu6+lL; 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 lk11-20020a17090b33cb00b002265c110dbasi1331067pjb.28.2023.01.06.03.55.45; Fri, 06 Jan 2023 03:55:52 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HAPu6+lL; 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 S233148AbjAFLaf (ORCPT + 54 others); Fri, 6 Jan 2023 06:30:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229737AbjAFLad (ORCPT ); Fri, 6 Jan 2023 06:30:33 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD9585FFC for ; Fri, 6 Jan 2023 03:30:28 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 3E50661D93 for ; Fri, 6 Jan 2023 11:30:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09CE9C433EF; Fri, 6 Jan 2023 11:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1673004627; bh=9eD0m84lTiwXGIY4mwU2neZ/1BkaOZj8Akj1zYIJJ0s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HAPu6+lL3woLdtod2IyCAmiIQ+xp1h5820d4H+f8l2WHKunXF+AinYH/4xDqYJeMl QvkdDnOEnSf6KGImlvP0cS/birdJ+1BZYf+twkM16FOAxc7lPvPtkm5aMm/HzX3x2e p/4sbt+1hgtdEHNDSle7X9MtcWtFY5VG37PVCyOc= Date: Fri, 6 Jan 2023 12:30:24 +0100 From: Greg Kroah-Hartman To: Hang Zhang Cc: Jiri Slaby , Ilpo =?iso-8859-1?Q?J=E4rvinen?= , Daniel Vetter , Yangxi Xiang , Xuezhi Zhang , Helge Deller , Tetsuo Handa , linux-kernel@vger.kernel.org Subject: Re: [PATCH] tty: vt: add some NULL checks for vc_data Message-ID: References: <20221229064153.23511-1-zh.nvgt@gmail.com> <182d36d5-df77-2479-882a-5bb588c5f170@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 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 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 Tue, Jan 03, 2023 at 10:01:15PM -0500, Hang Zhang wrote: > On Tue, Jan 3, 2023 at 4:24 AM Jiri Slaby wrote: > > > > On 29. 12. 22, 7:41, Hang Zhang wrote: > > > vc_selection(), do_blank_screen() and scrollfront() all access "vc_data" > > > structures obtained from the global "vc_cons[fg_console].d", which can > > > be freed and nullified (e.g., in the error path of vc_allocate()). But > > > these functions don't have any NULL checks against the pointers before > > > dereferencing them, causing potentially use-after-free or null pointer > > > dereference. > > > > Could you elaborate under what circumstances is fg_console set to a > > non-allocated console? > > Hi, Jiri, thank you for your reply! I am not a developer for tty > subsystem, so the reasoning here is based on my best-effort code > reading. Please correct me if I am wrong. > > This patch is based on several observations: > > (1) at the beginning of vc_selection() (where one NULL check is > inserted in this patch), poke_blanked_console() is invoked, which > explicitly checks whether "vc_cons[fg_console].d" is NULL, suggesting > the possibility of "fg_console" associated with an unallocated console > at this point. However, poke_blanked_console() returns "void", so > even if "fg_console" is NULL, after returning to vc_selection(), > it will just keep executing, resulting in the possible NULL pointer > dereference later ("vc" in vc_selection() can be "vc_cons[fg_console].d" > if called from set_selection_kernel()). So this patch actually tries > to make the already existing NULL check take effect on the control > flow (e.g., early return if NULL). But again, how can that value ever be NULL? And why are you returning "success" if it is? > (2) a similar NULL check for "vc_cons[fg_console].d" can also be found > in do_unblank_screen() ("if (!vc_cons_allocated(fg_console))") before > accessing the corresponding "vc_data". I do notice that the NULL check > has a comment "/* impossible */", but the check has not been removed so > far. My guess is that there might still be a chance that it can be > unallocated at that point. Please verify that this really ever could be NULL or not. thanks, greg k-h