From patchwork Wed Mar 11 09:16:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 11431189 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5ECED139A for ; Wed, 11 Mar 2020 09:16:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 47EA820848 for ; Wed, 11 Mar 2020 09:16:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728741AbgCKJQk (ORCPT ); Wed, 11 Mar 2020 05:16:40 -0400 Received: from mx2.suse.de ([195.135.220.15]:47794 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728671AbgCKJQj (ORCPT ); Wed, 11 Mar 2020 05:16:39 -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 B5069ADEB; Wed, 11 Mar 2020 09:16:37 +0000 (UTC) From: Takashi Iwai To: "James E . J . Bottomley" , "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Kashyap Desai , Sumit Saxena , Shivasharan S Subject: [PATCH 6/8] scsi: megaraid_sas: Use scnprintf() for avoiding potential buffer overflow Date: Wed, 11 Mar 2020 10:16:28 +0100 Message-Id: <20200311091630.22565-7-tiwai@suse.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200311091630.22565-1-tiwai@suse.de> References: <20200311091630.22565-1-tiwai@suse.de> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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(). Cc: Kashyap Desai Cc: Sumit Saxena Cc: Shivasharan S Signed-off-by: Takashi Iwai --- drivers/scsi/megaraid/megaraid_sas_base.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index 5bebdd397580..c3554bb12071 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -2987,7 +2987,8 @@ megasas_dump_sys_regs(void __iomem *reg_set, char *buf) u32 __iomem *reg = (u32 __iomem *)reg_set; for (i = 0; i < sz / sizeof(u32); i++) { - bytes_wrote += snprintf(loc + bytes_wrote, PAGE_SIZE, + bytes_wrote += scnprintf(loc + bytes_wrote, + PAGE_SIZE - bytes_wrote, "%08x: %08x\n", (i * 4), readl(®[i])); }