Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EF21C4CECE for ; Thu, 12 Mar 2020 11:40:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 31645206EB for ; Thu, 12 Mar 2020 11:40:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727050AbgCLLkF (ORCPT ); Thu, 12 Mar 2020 07:40:05 -0400 Received: from mx2.suse.de ([195.135.220.15]:47878 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725268AbgCLLkE (ORCPT ); Thu, 12 Mar 2020 07:40:04 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6A83CACC6; Thu, 12 Mar 2020 11:40:03 +0000 (UTC) Date: Thu, 12 Mar 2020 12:40:02 +0100 Message-ID: From: Takashi Iwai To: John Garry Cc: Takashi Iwai , "James E . J . Bottomley" , "Martin K . Petersen" , Subject: Re: [PATCH 7/8] scsi: core: Use scnprintf() for avoiding potential buffer overflow In-Reply-To: <3f9458e6-c00e-52c1-aa99-1a2845d13ed2@huawei.com> References: <20200311091630.22565-1-tiwai@suse.de> <20200311091630.22565-8-tiwai@suse.de> <3f9458e6-c00e-52c1-aa99-1a2845d13ed2@huawei.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org On Thu, 12 Mar 2020 10:25:11 +0100, John Garry wrote: > > On 11/03/2020 09:16, Takashi Iwai wrote: > > Since snprintf() returns the would-be-output size instead of the > > actual output size, the succeeding calls may go beyond the given > > buffer limit. Fix it by replacing with scnprintf(). > > > > Signed-off-by: Takashi Iwai > > --- > > drivers/scsi/scsi_sysfs.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c > > index c3a30ba4ae08..6b3644246d3a 100644 > > --- a/drivers/scsi/scsi_sysfs.c > > +++ b/drivers/scsi/scsi_sysfs.c > > @@ -1045,14 +1045,14 @@ sdev_show_blacklist(struct device *dev, struct device_attribute *attr, > > name = sdev_bflags_name[i]; > > if (name) > > - len += snprintf(buf + len, PAGE_SIZE - len, > > + len += scnprintf(buf + len, PAGE_SIZE - len, > > "%s%s", len ? " " : "", name); > > It would be nice to ensure that alignment with the parenthesis is maintained OK, will respin v2 with that change. thanks, Takashi