Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1627527pxv; Sat, 10 Jul 2021 09:59:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwC/AHCXPDr1Y2DPhpl5NnKOFFi+b8k2j2NfH37reQxPC84h9nZbH8IwiPAR5BFNFKI1sld X-Received: by 2002:a92:d943:: with SMTP id l3mr10023479ilq.37.1625936379233; Sat, 10 Jul 2021 09:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625936379; cv=none; d=google.com; s=arc-20160816; b=wjOaenCumwGeYObGNc/1zA1imGg0Dae7II9SNdmW9QCygDQHCyni9HbxcHvBp9F7mm KtPnzSMjLHI8DFkVogicofX0vKOsSFBJTsOTqmOedKoHusDu5ybnqmDdViTrY1Z1yVH3 8c70dEKEhE4u/mO9cIYYrFuBhRFBgYZX0X60qqFVHV9ZyjsCgqZeyD04vgiDrJIMIZSa fr0wX9P/qcKE9s4cAlWoo28pak0sIKuAUp5tBfEwxX3mnL6JmlhO8YBT9i+iQHK19OgU 9tYsnpYSk+WGTHkvX3YWInYXV5WMfSUANcp0F2j5/DPCaXxvQx3zIRvK6unw5MK4ChB6 NTUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=qa6HlYi2ySA9/PkG4//EBNInw6LnIjWbl1GZ6BqQIvM=; b=jsyR1KsQINvg6egC5FE03FUe4gYEsq34wjU89BOKxAvsoIlr+E9kndksTxB89pqJWS Z8di1rgnoMx7knw0f4hCGWuRJJK2a5uu7NYrp6lVF2yyEo0rcVKxv5wET2gyuqgmy8gk q/mIDAeCJU9kjRAq5JTXxrVzgJnpKx5+TvoisESqPgnLbGphCdLA2A5XAkO6z90/FQ4g A7yu2B1kw4sNgoFtxWVA7GdLKXybynFBaEe0WF5lQDANgbpVw3Gthkfr3AFCyx9sDVrA 04RrGpb+pqcjKc1gkOdMGDnqVwtAsd20s6djDSLJTIR2HYFsNyPLrw+1pGK2q8m26rgO fWGw== 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 e3si1466151iow.52.2021.07.10.09.59.27; Sat, 10 Jul 2021 09:59:39 -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 S229786AbhGJRBf (ORCPT + 99 others); Sat, 10 Jul 2021 13:01:35 -0400 Received: from smtprelay0154.hostedemail.com ([216.40.44.154]:57112 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229546AbhGJRBf (ORCPT ); Sat, 10 Jul 2021 13:01:35 -0400 Received: from omf03.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id 2274F18012002; Sat, 10 Jul 2021 16:58:49 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf03.hostedemail.com (Postfix) with ESMTPA id C8A9F13D93; Sat, 10 Jul 2021 16:58:47 +0000 (UTC) Message-ID: Subject: Re: [RESEND] edac: replace sprintf() by scnprintf() From: Joe Perches To: Salah Triki , bp@alien8.de, mchehab@kernel.org, tony.luck@intel.com, james.morse@arm.com, rric@kernel.org Cc: linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Date: Sat, 10 Jul 2021 09:58:46 -0700 In-Reply-To: <20210710163505.GA689509@pc> References: <20210710163505.GA689509@pc> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.0-1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: C8A9F13D93 X-Spam-Status: No, score=1.60 X-Stat-Signature: zbsk4wxe1dq9ow4qkp4dca31rg6w5x9f X-Rspamd-Server: rspamout02 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1+eE83VJUeJeyyUpGGi7QAvFfznHecaVyQ= X-HE-Tag: 1625936327-540020 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2021-07-10 at 17:35 +0100, Salah Triki wrote: > Replace sprintf() by scnprintf() in order to avoid buffer overflows. While of course safe, this is not strictly necessary as the maximum length of any edac_layer_name is 8 bytes. drivers/edac/edac_mc.c:const char *edac_layer_name[] = { drivers/edac/edac_mc.c- [EDAC_MC_LAYER_BRANCH] = "branch", drivers/edac/edac_mc.c- [EDAC_MC_LAYER_CHANNEL] = "channel", drivers/edac/edac_mc.c- [EDAC_MC_LAYER_SLOT] = "slot", drivers/edac/edac_mc.c- [EDAC_MC_LAYER_CHIP_SELECT] = "csrow", drivers/edac/edac_mc.c- [EDAC_MC_LAYER_ALL_MEM] = "memory", drivers/edac/edac_mc.c-}; And name is: char name[80]; I suppose name[80] could be changed to name[32] or so at the same time to reduce stack usage. Maybe name should be moved into the loop too. --- drivers/edac/debugfs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/edac/debugfs.c b/drivers/edac/debugfs.c index 4804332d99465..a41071f2ad428 100644 --- a/drivers/edac/debugfs.c +++ b/drivers/edac/debugfs.c @@ -55,14 +55,15 @@ void edac_debugfs_exit(void) void edac_create_debugfs_nodes(struct mem_ctl_info *mci) { struct dentry *parent; - char name[80]; int i; parent = debugfs_create_dir(mci->dev.kobj.name, edac_debugfs); for (i = 0; i < mci->n_layers; i++) { - sprintf(name, "fake_inject_%s", - edac_layer_name[mci->layers[i].type]); + char name[32]; + + scnprintf(name, sizeof(name), "fake_inject_%s", + edac_layer_name[mci->layers[i].type]); debugfs_create_u8(name, S_IRUGO | S_IWUSR, parent, &mci->fake_inject_layer[i]); }