From patchwork Tue Oct 18 15:13:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1691581 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=LQD2bSCk; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MsHT12J9Kz23kT for ; Wed, 19 Oct 2022 02:14:12 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1okoI8-0000ok-Nd; Tue, 18 Oct 2022 15:14:04 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1okoI6-0000oL-OS for kernel-team@lists.ubuntu.com; Tue, 18 Oct 2022 15:14:02 +0000 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id D56CF3F367 for ; Tue, 18 Oct 2022 15:14:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1666106041; bh=tzn1M2JlIbb5wLlY48PTg/IV9RDjw5S1+M7mTCts6qE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=LQD2bSCkH+9huJVkcRkaXJqujPTe0WgxTpg98E2OrnSFRaGuo7J0175BODarVBzc+ Cd0qWpz6/K6PaIqHykGApGlkCVMG02B7Q1NPcPln8IbiS1Tn4IqJBJAhnOaukAsspK 5DQ9iF765LYFMeEDfzollSuHsFXW3PF6Kth762BxOcEZghHaGb7Z9qYL3XU3nIFBSR xjLO5/qa4kaoy2GgSAIOhvrJtjuiQ0nkSwMnkqKM1jqmBEVKYrYRGyV0NpOkPL3aOC aUt2zOdVJcMWl/KuuCyPAibJruqd/RcD77kf7tVGYTNrk1FvHZpDMmire3Kkwi7NwC pBdfYLp2SC7Sw== Received: by mail-pj1-f70.google.com with SMTP id mq15-20020a17090b380f00b0020ad26fa5edso11954239pjb.7 for ; Tue, 18 Oct 2022 08:14:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tzn1M2JlIbb5wLlY48PTg/IV9RDjw5S1+M7mTCts6qE=; b=m2UkEgdXsA3iSbaKl0rr2l8Yp6ApI4Rup2fdGuU9hRkhsyIeG8ngbxzNDp4dDYqdlt 5GG8WWks1fpx3WweFK1t99DFbzcBcqnPK6THM+6Buq+wOJLvNsPcvCuPHdJxRjAeOFaJ F1dwA16WpP7mY9wpkiI2inZt08cygGvSIFH6079s8OS0gAzrW/n5htqIf64PrK9zal/g 3uSKCjTWdPdlbqgYjrPUyKnlzYmZjOjcK4qGs4CUQtdMbdYnikAHS8pE5LQ2kbqMjbwD J1EC0++YWlLjGga99nGrM9ISsNtYySnvATnlw9uF5r9vm/UzmTT4uAmSjIvHRRUznaYI +MTQ== X-Gm-Message-State: ACrzQf2QCBNTdhAo4iAse7NrXR0E6tw4HkYCJSVhRg/6ZWbCqDzgSQjc aCCkPzLxR07pDlhiurd8TRuBg2MEzBHDVsZSYBEYPLqKLHe/PZWMUnZsUrtwvqLFYmliiR5ORef QZTS/TdgIPTCt5kEDntXpAwcI3jKXosdKAVdEdEvlaA== X-Received: by 2002:a05:6a00:2446:b0:528:5da9:cc7 with SMTP id d6-20020a056a00244600b005285da90cc7mr3758123pfj.51.1666106039744; Tue, 18 Oct 2022 08:13:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6rxodIppjDjB0G4cNIm5BrgDjjcXAoZFq4tmEuo/tk0v8gchIZs3jDmBxOjsPaU9WLhDRMTQ== X-Received: by 2002:a05:6a00:2446:b0:528:5da9:cc7 with SMTP id d6-20020a056a00244600b005285da90cc7mr3758097pfj.51.1666106039393; Tue, 18 Oct 2022 08:13:59 -0700 (PDT) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id w11-20020a170902ca0b00b0017f7fa6808csm8840019pld.87.2022.10.18.08.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 08:13:58 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH][kinetic linux] md: Replace snprintf with scnprintf Date: Tue, 18 Oct 2022 09:13:17 -0600 Message-Id: <20221018151318.167543-2-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221018151318.167543-1-tim.gardner@canonical.com> References: <20221018151318.167543-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Saurabh Sengar BugLink: https://bugs.launchpad.net/bugs/1993315 Current code produces a warning as shown below when total characters in the constituent block device names plus the slashes exceeds 200. snprintf() returns the number of characters generated from the given input, which could cause the expression “200 – len” to wrap around to a large positive number. Fix this by using scnprintf() instead, which returns the actual number of characters written into the buffer. [ 1513.267938] ------------[ cut here ]------------ [ 1513.267943] WARNING: CPU: 15 PID: 37247 at /lib/vsprintf.c:2509 vsnprintf+0x2c8/0x510 [ 1513.267944] Modules linked in: [ 1513.267969] CPU: 15 PID: 37247 Comm: mdadm Not tainted 5.4.0-1085-azure #90~18.04.1-Ubuntu [ 1513.267969] Hardware name: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS Hyper-V UEFI Release v4.1 05/09/2022 [ 1513.267971] RIP: 0010:vsnprintf+0x2c8/0x510 <-snip-> [ 1513.267982] Call Trace: [ 1513.267986] snprintf+0x45/0x70 [ 1513.267990] ? disk_name+0x71/0xa0 [ 1513.267993] dump_zones+0x114/0x240 [raid0] [ 1513.267996] ? _cond_resched+0x19/0x40 [ 1513.267998] raid0_run+0x19e/0x270 [raid0] [ 1513.268000] md_run+0x5e0/0xc50 [ 1513.268003] ? security_capable+0x3f/0x60 [ 1513.268005] do_md_run+0x19/0x110 [ 1513.268006] md_ioctl+0x195e/0x1f90 [ 1513.268007] blkdev_ioctl+0x91f/0x9f0 [ 1513.268010] block_ioctl+0x3d/0x50 [ 1513.268012] do_vfs_ioctl+0xa9/0x640 [ 1513.268014] ? __fput+0x162/0x260 [ 1513.268016] ksys_ioctl+0x75/0x80 [ 1513.268017] __x64_sys_ioctl+0x1a/0x20 [ 1513.268019] do_syscall_64+0x5e/0x200 [ 1513.268021] entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fixes: 766038846e875 ("md/raid0: replace printk() with pr_*()") Reviewed-by: Michael Kelley Acked-by: Guoqing Jiang Signed-off-by: Saurabh Sengar Signed-off-by: Song Liu (cherry picked from commit 1727fd5015d8f93474148f94e34cda5aa6ad4a43) Signed-off-by: Tim Gardner --- drivers/md/raid0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c index 99db36730e78..ad6ad9df40fb 100644 --- a/drivers/md/raid0.c +++ b/drivers/md/raid0.c @@ -47,7 +47,7 @@ static void dump_zones(struct mddev *mddev) int len = 0; for (k = 0; k < conf->strip_zone[j].nb_dev; k++) - len += snprintf(line+len, 200-len, "%s%pg", k?"/":"", + len += scnprintf(line+len, 200-len, "%s%pg", k?"/":"", conf->devlist[j * raid_disks + k]->bdev); pr_debug("md: zone%d=[%s]\n", j, line);