Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1840931imm; Thu, 18 Oct 2018 05:15:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV60jcqSczYqBeipIc1AgbN66WoyXCBKGqpTO8gYRUQOB4/flxurNOKdH8RU7DoBbzbCzkYG+ X-Received: by 2002:a17:902:5597:: with SMTP id g23-v6mr1674169pli.46.1539864952234; Thu, 18 Oct 2018 05:15:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539864952; cv=none; d=google.com; s=arc-20160816; b=xDlWRAzEOab5C3LflSNn5FHoe5AwsaobdokYSr2OM3skrTfOutX9MIkksW0FYC6NkA jlEsJpfi1t9gyzessnTL1DJOT+Px9wLY1aBybl1Liq9fThWjBcHNFVEkHf662JEOifdn VZRF9dq1b+Sa4o6Vvyb/EF/0X6zED2lZGh2sVAVmASNqYZkltxG/inhAYZkM/fEfcVJI ZUE9TnzV/DhqmgnZhIeY68rUJ8KWPC4wQmUlDG+Xa0LM2r+CovN4de527vbnWUou5qBC TSA4Ahgmc+lUMJ3GILzfjFwx5kZh/z/HBlCpkBPSatdWIbYW1vQVUsNf8MAx2C7SpJ7p RPVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=+zsW2uOKyzZD42Y1R8BO3PbH17QXOzXG/TbB0Nhq7UU=; b=aeJHmSyivJFK6RWIfuEXWO3ho/v9aivzgqwj6gVNk0qySniC4qUP31ueOoaHjnR8H8 asWdBGT8uo8MH+03kqZZLmtwJH+Cyt2awQC04ZACa+S3o1iOCXoyFf3204QW5PTQ1HPk MMUWZWYYo8G5dtUWep6Lo3k4+LLCOEBL2Vv/2dKsp2cU5vcItU/8TtW8FFpl1CZsaWjl bLB8/E+ZFCSkjpckjB6M8Qf2SCn8RID2Bf3hOFh0eqXtLPpDUL13zFHG4D4TB1iGbRDa 4jEp8lEfHTP96CqFL3gA0uUs7tDfIRQwA2t8svZ3LBepnMHBUGgUpDZcP14jsyGZGFc6 xu1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g16-v6si20331437pgd.354.2018.10.18.05.15.35; Thu, 18 Oct 2018 05:15:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726609AbeJRUPu (ORCPT + 99 others); Thu, 18 Oct 2018 16:15:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48452 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726325AbeJRUPu (ORCPT ); Thu, 18 Oct 2018 16:15:50 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ADEEE305B885; Thu, 18 Oct 2018 12:15:05 +0000 (UTC) Received: from prarit.bos.redhat.com (prarit-guest.khw1.lab.eng.bos.redhat.com [10.16.200.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id E986F8A0E8; Thu, 18 Oct 2018 12:15:04 +0000 (UTC) Subject: Re: [PATCH v2] kdb: Use strscpy with destination buffer size To: Daniel Thompson Cc: linux-kernel@vger.kernel.org, Jonathan Toppins , Jason Wessel , kgdb-bugreport@lists.sourceforge.net References: <20180920125914.17920-1-prarit@redhat.com> <9192af58-7966-c023-8b19-5b291839a228@linaro.org> <78793735-c2ce-62f6-d745-5fc06a17beb1@redhat.com> <20181004124535.narksjioip7zo7ha@holly.lan> From: Prarit Bhargava Message-ID: <8c6b6666-e5fd-49cd-b357-f491b517d4a3@redhat.com> Date: Thu, 18 Oct 2018 08:15:04 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20181004124535.narksjioip7zo7ha@holly.lan> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 18 Oct 2018 12:15:05 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/04/2018 08:45 AM, Daniel Thompson wrote: > On Thu, Oct 04, 2018 at 08:25:30AM -0400, Prarit Bhargava wrote: >> On 10/02/2018 11:53 AM, Daniel Thompson wrote: >>> On 20/09/2018 13:59, Prarit Bhargava wrote: >>>> gcc 8.1.0 warns with: >>>> >>>> kernel/debug/kdb/kdb_support.c: In function ‘kallsyms_symbol_next’: >>>> kernel/debug/kdb/kdb_support.c:239:4: warning: ‘strncpy’ specified bound >>>> depends on the length of the source argument [-Wstringop-overflow=] >>>>       strncpy(prefix_name, name, strlen(name)+1); >>>>       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>>> kernel/debug/kdb/kdb_support.c:239:31: note: length computed here >>>> >>>> Use strscpy() with the destination buffer size, and use ellipses when >>>> displaying truncated symbols. >>>> >>>> v2: Use strscpy() >>>> >>>> Signed-off-by: Prarit Bhargava >>>> Cc: Jonathan Toppins >>>> Cc: Jason Wessel >>>> Cc: Daniel Thompson >>>> Cc: kgdb-bugreport@lists.sourceforge.net >>>> --- >>>>   kernel/debug/kdb/kdb_io.c      | 15 +++++++++------ >>>>   kernel/debug/kdb/kdb_private.h |  2 +- >>>>   kernel/debug/kdb/kdb_support.c | 10 +++++----- >>>>   3 files changed, 15 insertions(+), 12 deletions(-) >>>> >>>> diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c >>>> index ed5d34925ad0..6a4b41484afe 100644 >>>> --- a/kernel/debug/kdb/kdb_io.c >>>> +++ b/kernel/debug/kdb/kdb_io.c >>>> @@ -216,7 +216,7 @@ static char *kdb_read(char *buffer, size_t bufsize) >>>>       int count; >>>>       int i; >>>>       int diag, dtab_count; >>>> -    int key; >>>> +    int key, buf_size, ret; >>>>           diag = kdbgetintenv("DTABCOUNT", &dtab_count); >>>> @@ -336,9 +336,8 @@ static char *kdb_read(char *buffer, size_t bufsize) >>>>           else >>>>               p_tmp = tmpbuffer; >>>>           len = strlen(p_tmp); >>>> -        count = kallsyms_symbol_complete(p_tmp, >>>> -                         sizeof(tmpbuffer) - >>>> -                         (p_tmp - tmpbuffer)); >>>> +        buf_size = sizeof(tmpbuffer) - (p_tmp - tmpbuffer); >>>> +        count = kallsyms_symbol_complete(p_tmp, buf_size); >>>>           if (tab == 2 && count > 0) { >>>>               kdb_printf("\n%d symbols are found.", count); >>>>               if (count > dtab_count) { >>>> @@ -350,9 +349,13 @@ static char *kdb_read(char *buffer, size_t bufsize) >>>>               } >>>>               kdb_printf("\n"); >>>>               for (i = 0; i < count; i++) { >>>> -                if (WARN_ON(!kallsyms_symbol_next(p_tmp, i))) >>>> +                ret = kallsyms_symbol_next(p_tmp, i, buf_size); >>>> +                if (WARN_ON(!ret)) >>>>                       break; >>> I'm getting confused by having two different branches on ret. >>> >>> Don't get a WARN_ON() when ret == -E2BIG? >>> >>> >> >> Should we WARN on a really long symbol? I don't think we should as we're >> handling that by truncating the output and adding ellipses below. > > It's OK. You describe the behaviour I expect but I was misreading the > code (not realizing that kallsyms_symbol_next() had not become a 0 on > success success function). > > However after reviewing the code (properly this time) I wonder if the > WARN_ON() should be improved to match the return value for the function: > > WARN_ON(ret >= 0 && ret < len) > > That said, checking the symbol length is pretty paranoid and getting > close to nitpicking so I'll leave it up to you and, with or without, the > change: > > Reviewed-by: Daniel Thompson > > I think we should leave it as is for now. OOC was this patch picked up by anyone's repo for staging for 4.20? P. > Daniel. >