From mboxrd@z Thu Jan 1 00:00:00 1970 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 11F7DC10F27 for ; Wed, 11 Mar 2020 07:32:31 +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 E7805208C3 for ; Wed, 11 Mar 2020 07:32:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E7805208C3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=amd-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9B1B989C8F; Wed, 11 Mar 2020 07:32:30 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 17E6689C8F for ; Wed, 11 Mar 2020 07:32:30 +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 CC862AF0D; Wed, 11 Mar 2020 07:32:28 +0000 (UTC) Date: Wed, 11 Mar 2020 08:32:28 +0100 Message-ID: From: Takashi Iwai To: Alex Deucher Subject: Re: [PATCH 1/5] drm/amdgpu/pm: Use scnprintf() for avoiding potential buffer overflow In-Reply-To: <20200311072904.6363-1-tiwai@suse.de> References: <20200311072904.6363-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: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Zhou , Christian =?UTF-8?B?S8O2bmln?= , amd-gfx@lists.freedesktop.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" BTW, please ignore the subject prefix '[1/5]', which was added mistakenly while extracting a patch from the commit list. This is a single patch. thanks, Takashi On Wed, 11 Mar 2020 08:29:04 +0100, 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(). > > Also adjust the size argument passed to scnprintf() so that it really > cuts off at the right remaining buffer length. > > Signed-off-by: Takashi Iwai > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c > index bc3cf04a1a94..4a737d074f4b 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c > @@ -448,7 +448,7 @@ static ssize_t amdgpu_get_pp_num_states(struct device *dev, > > buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums); > for (i = 0; i < data.nums; i++) > - buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i, > + buf_len += scnprintf(buf + buf_len, PAGE_SIZE - buf_len, "%d %s\n", i, > (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" : > (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" : > (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" : > -- > 2.16.4 > _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx