Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2552724imu; Thu, 29 Nov 2018 06:48:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/W5TeeGq+MEXX6/P8y+P61sS/AAmHIa/SZMElq3/tNf4UDVsjEKtj0Oa7T9hHPlQZOBbCZN X-Received: by 2002:a17:902:a70b:: with SMTP id w11mr1755994plq.84.1543502882346; Thu, 29 Nov 2018 06:48:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543502882; cv=none; d=google.com; s=arc-20160816; b=U/f85uJ8gETGuvjYtGBBi9BMfGABufbzla4ViQm0gKG9o77jfaUs9jOrthAhqWp0JS 7e2mZXtVtwH2+p9Nu0lF0ZMB40MoE2qfv4RJaPJCfLptx6GuMoNAv6FElQXHWjWYQ1De 0O2L+pmQqhznCSTbcev61N3Dc4U+3kvKEdXMXYkr0VsYeWXlZPLnOv2d845OgithqZms 3Uc7kjQS3QMElkS1a/hQbFHuO2tM9Dy03+cGgktbwomBNRSJ7/kzAfWH9fvMDPUZkwQe eQlA4sBFGJTKJajReALzqd1gYtVss7UkS6WhAIjGuIJK25lF6zmZcu/q/o/dCfq1JpAw PYTQ== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=La2bsc8EL/9yA1IOG3wqOXeRGh2VtGJLDnZTosmwyno=; b=qnyNckKLKJvrZVKmoJ+me3w+DyeyPipNakfCI2S25h1BPOF5fiXr+A+Z2z2mnLeALj dxhH8APdwAcOW3CLM5JDTrtsMRJB63HNlL89+wbi0MUuuN/Z3ZxjsWqhxvIairGlEVsj tCHetLtgrzs4wd8WNzxxSD+pFxQV1yRW2qiPfrLSneXq5Rawi35/pcpIKJonDKR75eZY DCJrIQNdZc5VskuL5CO4arKXG5PK77fYcU8lhbpKNdy3ocrHIi2etjBSwYIG2pSKfHht QtHes2HbEf9cnk25Lr0SasXGmiB9uiuQsUbCRSyNnagRJ5kG8yAjh2+Ms44TGTd1AVfs cDaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=svK7cntf; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g33si2111410pgm.426.2018.11.29.06.47.47; Thu, 29 Nov 2018 06:48:02 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=svK7cntf; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733295AbeK3BcA (ORCPT + 99 others); Thu, 29 Nov 2018 20:32:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:59820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728574AbeK3Bb7 (ORCPT ); Thu, 29 Nov 2018 20:31:59 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 721622133F; Thu, 29 Nov 2018 14:26:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501586; bh=vhPuVxessv532O79CgtPwTEhrejhfqOXPSQzrqMjiNs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=svK7cntfoeIDu2de4xumbQYocQrHpxy0Y1vWgJThXt8QF0MA8YntasL8mZhJTkEbi GM7ukRP9XJ8+L9w99eqgR0vw6op3s0UgJDeaVhBbQb3E49ijQ6/5laFIr3Hia8GRmY G9y9cA86WFnL/CwD9is+XD/eI6IHoHgcathftPC4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Prarit Bhargava , Jonathan Toppins , Jason Wessel , Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, Sasha Levin Subject: [PATCH 4.14 059/100] kdb: Use strscpy with destination buffer size Date: Thu, 29 Nov 2018 15:12:29 +0100 Message-Id: <20181129140104.178001855@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140058.768942700@linuxfoundation.org> References: <20181129140058.768942700@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit c2b94c72d93d0929f48157eef128c4f9d2e603ce ] 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 Reviewed-by: Daniel Thompson Signed-off-by: Daniel Thompson Signed-off-by: Sasha Levin --- 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 @@ poll_again: 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 @@ poll_again: } 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; - 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) diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h index fc224fbcf954..f2158e463a0f 100644 --- a/kernel/debug/kdb/kdb_private.h +++ b/kernel/debug/kdb/kdb_private.h @@ -83,7 +83,7 @@ typedef struct __ksymtab { unsigned long sym_start; unsigned long sym_end; } kdb_symtab_t; -extern int kallsyms_symbol_next(char *prefix_name, int flag); +extern int kallsyms_symbol_next(char *prefix_name, int flag, int buf_size); extern int kallsyms_symbol_complete(char *prefix_name, int max_len); /* Exported Symbols for kernel loadable modules to use. */ diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c index 84422d2b95c0..014f6fbb3832 100644 --- a/kernel/debug/kdb/kdb_support.c +++ b/kernel/debug/kdb/kdb_support.c @@ -221,11 +221,13 @@ int kallsyms_symbol_complete(char *prefix_name, int max_len) * Parameters: * prefix_name prefix of a symbol name to lookup * flag 0 means search from the head, 1 means continue search. + * buf_size maximum length that can be written to prefix_name + * buffer * Returns: * 1 if a symbol matches the given prefix. * 0 if no string found */ -int kallsyms_symbol_next(char *prefix_name, int flag) +int kallsyms_symbol_next(char *prefix_name, int flag, int buf_size) { int prefix_len = strlen(prefix_name); static loff_t pos; @@ -235,10 +237,8 @@ int kallsyms_symbol_next(char *prefix_name, int flag) pos = 0; while ((name = kdb_walk_kallsyms(&pos))) { - if (strncmp(name, prefix_name, prefix_len) == 0) { - strncpy(prefix_name, name, strlen(name)+1); - return 1; - } + if (!strncmp(name, prefix_name, prefix_len)) + return strscpy(prefix_name, name, buf_size); } return 0; } -- 2.17.1