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 1FFD3C10F27 for ; Wed, 11 Mar 2020 08:24:05 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F1778206B7 for ; Wed, 11 Mar 2020 08:24:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1778206B7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7188C8999A; Wed, 11 Mar 2020 08:24:04 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 558768999A for ; Wed, 11 Mar 2020 08:24:03 +0000 (UTC) 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 0380AB2CC; Wed, 11 Mar 2020 08:24:01 +0000 (UTC) Date: Wed, 11 Mar 2020 09:24:01 +0100 Message-ID: From: Takashi Iwai To: Thomas Zimmermann Subject: Re: [PATCH] drm: sysfs: Use scnprintf() for avoiding potential buffer overflow In-Reply-To: References: <20200311073540.7108-1-tiwai@suse.de> 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") X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dri-devel@lists.freedesktop.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Wed, 11 Mar 2020 09:10:56 +0100, Thomas Zimmermann wrote: > > Hi Takashi > > Am 11.03.20 um 08:35 schrieb Takashi Iwai: > > 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/gpu/drm/drm_sysfs.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c > > index dd2bc85f43cc..9b3180e8c12f 100644 > > --- a/drivers/gpu/drm/drm_sysfs.c > > +++ b/drivers/gpu/drm/drm_sysfs.c > > @@ -230,7 +230,7 @@ static ssize_t modes_show(struct device *device, > > > > mutex_lock(&connector->dev->mode_config.mutex); > > list_for_each_entry(mode, &connector->modes, head) { > > - written += snprintf(buf + written, PAGE_SIZE - written, "%s\n", > > + written += scnprintf(buf + written, PAGE_SIZE - written, "%s\n", > > mode->name); > > } > > mutex_unlock(&connector->dev->mode_config.mutex); > > > > In drm_sysfs.c, there are more _show functions with calls to snprintf() > that could be replaced by scnprintf(). ATM they don't return the correct > length for output that exceeds PAGE_SIZE. since you're at it, you may > replace them as well. Well, the rest snprintf() calls are single calls and can't be over PAGE_SIZE obviously. IOW, they could be rather replaced with sprintf() instead, for a sake of simplicity. > But in any case > > Reviewed-by: Thomas Zimmermann > > for this patch. > > Do you want me to merge the patch into drm-misc-next? Yes, please. thanks, Takashi _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel