Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2987499ybt; Mon, 29 Jun 2020 12:11:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvhIE6FJZAC7KpF4/R9rN4o3g3ZJ70N8v0wiCDas6mCwyA6K6h1vT8GvmVBXa8zBoSl6wy X-Received: by 2002:a05:6402:1ef:: with SMTP id i15mr1551450edy.378.1593457916651; Mon, 29 Jun 2020 12:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593457916; cv=none; d=google.com; s=arc-20160816; b=U4iKdhKOWjMj8fZMlkKHLLM6bzrZaD+zQfhseTmknTCD6+YjcCRWUuPoGyc8ZNJbBN tFUWtSiDk8lZpEZCMCbVV8sFGjW5Zxv2aDgZwptTup08yjkR87PyQHIrtX1Bzlnlj1wm 7QfcrOR+aznN+aadmRvo8CExtHSbRlkaf0/6DhMsqu1mjmNwYqzv8j5ugZF4u42tqDDu OUJRi71h9U6AiW+NnXeQFOcdJ16OZ5fLbwcMVwKFUBJoa3VEgnY3glhQMrt408wz+bFC jXboLJlaIv1G/yxnnYbIk36zFEN8u2BpTUtvP4B6dNA00QcARBRWt7+jbSzle1m+pEhM 5XJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=1MD+CHIuaFM4exKvf1k4Emhh9AT26TRsh0T+8UdO7TI=; b=Zqekk34ddLIeZiKnqLNUuDXfpItm9xmiFm+yP/X0B82WBAQANEjdBaeKfJhMx3DhX+ SXLO6A5+hsb9fsQWnf6jjlhqwfrb7slZBfCHXOkTbP90I/ih7dWjLkg9DxUzgFsxvlUo tVODyQTK5k6Sodxx94Am86cK6WlSPXb9ZtiCkWWhzRg7YvqUpgaCcAvRmxlJbADbpwXT p2TPEr5CjRegNWqp6IJB6m1SqsG3XwSGZYPwl/5MZXUTup2KSw8CT/xkAtF0Q4UQoWlT V/TaBRNuy1EHcKuXVCIWUABgu7fxfmfuPqwMCz2U6BVH8NxSis60mCl2UitZBCTEFFQw OoBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d13si239575edz.257.2020.06.29.12.11.33; Mon, 29 Jun 2020 12:11:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730558AbgF2TLa (ORCPT + 99 others); Mon, 29 Jun 2020 15:11:30 -0400 Received: from mx2.suse.de ([195.135.220.15]:53726 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731050AbgF2TL2 (ORCPT ); Mon, 29 Jun 2020 15:11:28 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CA548AD5C; Mon, 29 Jun 2020 14:53:52 +0000 (UTC) Date: Mon, 29 Jun 2020 16:53:51 +0200 From: Petr Mladek To: Cengiz Can , Daniel Thompson , Sumit Garg Cc: Jason Wessel , Douglas Anderson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, Andy Shevchenko Subject: Re: [PATCH] kdb: prevent possible null deref in kdb_msg_write Message-ID: <20200629145350.GC6173@alley> References: <20200629135923.14912-1-cengiz@kernel.wtf> <20200629145020.GL6156@alley> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200629145020.GL6156@alley> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 2020-06-29 16:50:20, Petr Mladek wrote: > On Mon 2020-06-29 16:59:24, Cengiz Can wrote: > > `kdb_msg_write` operates on a global `struct kgdb_io *` called > > `dbg_io_ops`. > > > > Although it is initialized in `debug_core.c`, there's a null check in > > `kdb_msg_write` which implies that it can be null whenever we dereference > > it in this function call. > > > > Coverity scanner caught this as CID 1465042. > > > > I have modified the function to bail out if `dbg_io_ops` is not properly > > initialized. > > > > Signed-off-by: Cengiz Can > > --- > > kernel/debug/kdb/kdb_io.c | 15 ++++++++------- > > 1 file changed, 8 insertions(+), 7 deletions(-) > > > > diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c > > index 683a799618ad..85e579812458 100644 > > --- a/kernel/debug/kdb/kdb_io.c > > +++ b/kernel/debug/kdb/kdb_io.c > > @@ -549,14 +549,15 @@ static void kdb_msg_write(const char *msg, int msg_len) > > if (msg_len == 0) > > return; > > > > - if (dbg_io_ops) { > > - const char *cp = msg; > > - int len = msg_len; > > + if (!dbg_io_ops) > > + return; > > This looks wrong. The message should be printed to the consoles > even when dbg_io_ops is NULL. I mean that the for_each_console(c) > cycle should always get called. Please, forget this mail. Daniel explained that dbg_io_ops must have been set when this function gets called. I am sorry for the noise. Best Regards, Petr