Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp907400imm; Thu, 4 Oct 2018 05:25:54 -0700 (PDT) X-Google-Smtp-Source: ACcGV60xN8IImevfur+SWCWjsMKuB4wjNhqZwpviEmDvovYHGtgibkXgAjj+LBhEek9WswjsOLTF X-Received: by 2002:a17:902:8eca:: with SMTP id x10-v6mr6428838plo.336.1538655954612; Thu, 04 Oct 2018 05:25:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538655954; cv=none; d=google.com; s=arc-20160816; b=POkikxyzJthH1EDC795Ont0oh+tgWh03hwpUi6DPxixqGb0IU2AUPdIzC/Szefq3ix eda3lnQi9jPQber9dCVYOiEWVBqwlmc1UyoeoA2bI13vn8qCTuokdI6suYpRON30hoZH yaNChZ+pqG/7lKEJi5bRRjYEUQs/K6nFFRwL8iBvXBPi+3I9x6XFrVLmnquHk5TljsKo hBZmzokZ4OldGpscrXVfpGP+A+WzEiW7foxJyOOpj1ocRgoLRhmvnAG8L9MdLeSCK/tS VwC2ZKtYNAm0GOrwXWQDtzdHu0hJ5FjMRHVPp5tDpJRPMYxfYkkEGc8NR5REn16JGPyl TbZA== 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=JqyFTi+B+6DcwLeQA8DK38eunOevPDkbKBy7lTBmVDA=; b=HOAEhSs/+azprzIdcS65wfPrQzZX4vEQWGCBsHEN7xhYVSwnI7YszOOG+kaRIsK1oh /fUzl4hj4gwxAC30r4cz1iUm94UJU87aM1dCVgdYaLjmcijd4Tq3+2LPDc73AbuTQ/yh Xm3H1uabKG1M04fV0sBiSDy6C8Em+ASDCMIBn6qbLCkJDBNqQ2RhKUQZoJFf+3KRRu+5 XgEDGDaVvozQlIVi3n4fnmxoSI8rORLAe9+/IbenQGMyqislpcxHH+Mp6EM6ZJl/0Mnb /6Sub5I5Dy2mPF4WYDbEktM49e5pqyM7zYtQ+3rtI5I3KjwbwIsJ/BoNcNjK/R8ncK/o c8XA== 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 p17-v6si4100445pgj.416.2018.10.04.05.25.38; Thu, 04 Oct 2018 05:25:54 -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 S1727586AbeJDTSe (ORCPT + 99 others); Thu, 4 Oct 2018 15:18:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33418 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727369AbeJDTSe (ORCPT ); Thu, 4 Oct 2018 15:18:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 683A48830C; Thu, 4 Oct 2018 12:25:31 +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 CD6C84A7; Thu, 4 Oct 2018 12:25:30 +0000 (UTC) Subject: Re: [PATCH v2] kdb: Use strscpy with destination buffer size To: Daniel Thompson , linux-kernel@vger.kernel.org Cc: Jonathan Toppins , Jason Wessel , kgdb-bugreport@lists.sourceforge.net References: <20180920125914.17920-1-prarit@redhat.com> <9192af58-7966-c023-8b19-5b291839a228@linaro.org> From: Prarit Bhargava Message-ID: <78793735-c2ce-62f6-d745-5fc06a17beb1@redhat.com> Date: Thu, 4 Oct 2018 08:25:30 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <9192af58-7966-c023-8b19-5b291839a228@linaro.org> 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 04 Oct 2018 12:25:31 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. P. > Daniel. > > >> -                kdb_printf("%s ", p_tmp); >> +                if (ret != -E2BIG) >> +                    kdb_printf("%s ", p_tmp); >> +                else >> +                    kdb_printf("%s... ", p_tmp); >>                   *(p_tmp + len) = '\0'; >>               } >>               if (i >= dtab_count)