Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1312321rdd; Wed, 10 Jan 2024 15:58:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTJcyEKnAE/BtalzQnDQAS7b/yXGQK4vEBw1YJalwHJYddfrZ7hMYZoDBRzzLJm1drGeQV X-Received: by 2002:a9d:6409:0:b0:6dd:db4e:93e8 with SMTP id h9-20020a9d6409000000b006dddb4e93e8mr515584otl.28.1704931109905; Wed, 10 Jan 2024 15:58:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704931109; cv=none; d=google.com; s=arc-20160816; b=WA+h5NKDB1HkXrPranYcS/wNKsAQT9tSN3EaFlOGM9Ax3J2C24UiEOnNjSpWvNVnfy Cjxvrn00BMuZVOS9CizqU+XPGMQmyRxqvjex1R8DLUIO6+lnC2Ch9QNVpkbKXg7je8gQ 96asEvBALKYeEsDVSolo9kq2MKh+sdmjY+mVEWoWQH6UBR7hSpzcrMH5wGibXu5K/zl1 tHcYxWBzEcFEagHFtqU/+eb+2CWTC1E+adshEZOjgQv51wxpwOW4BkUJEGSmYhMMNiyC YZg2o4piuwBw9ehXnPQOEeVoL4utE9TrKOaKMI65g+2tUiUQGVYVJqK1eNCRYbptLXzY 9+bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hRtOehh8h5mmIfnUBPPWvn4/oVyBLE/rm2Y8lVByjVU=; fh=ODrzvDAN8C7hsSytudlayxZVS6GEQidagfQ1JcgjAp0=; b=R99LQISBKm1ZfFBw+6rBJwQVSEBFgLxL1hpcF0ItH+br3Gje5ibdZKW80ZW6yNxT6A /XkW6wvbTx9inIl3iz3NNCHATlqwbtXet7xu/m8Ka8qoihHfh/VmTjkv3bRmFd939+ru 6mxAliakEB/PwGb/3EuImElYGEepHHT7pjthi9Tj0qCdduPCZcf9bYor2NSwntwxckvQ bEKhg8AiWUAJeZWEQc3EO7ybROKl+zo/p/7jZ2kX+Z1WorjUBhVZB86nhdPiphHgoa2h D35eMjms+NzP/chH0kGI7Ehv9cLvE0RExgL2N3/HYcm6gd42zaRs3h/O/assb98wCGX4 4tag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="YnPSb/DR"; spf=pass (google.com: domain of linux-kernel+bounces-22898-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22898-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id g8-20020a63e608000000b005cd84f2c7a9si4517249pgh.763.2024.01.10.15.58.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 15:58:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22898-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="YnPSb/DR"; spf=pass (google.com: domain of linux-kernel+bounces-22898-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22898-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 47E422836D9 for ; Wed, 10 Jan 2024 23:58:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3AA804F8B3; Wed, 10 Jan 2024 23:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="YnPSb/DR" Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 384C14EB41 for ; Wed, 10 Jan 2024 23:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6daa822be30so2204963b3a.0 for ; Wed, 10 Jan 2024 15:58:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1704931099; x=1705535899; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=hRtOehh8h5mmIfnUBPPWvn4/oVyBLE/rm2Y8lVByjVU=; b=YnPSb/DR6HN646/sa64ezlsYwMQ0cdu5aDq4ROCOySZUAOuyi074zA4dmrVypjJi8d BN3VzRRqb1VIDii74DqVfdmTMpkQk5RMAsKB0SWfj2HCZ3F1qtW7Zvb42nP1ifpM5SPz G/TNFgRNkm5J1SHLCW7OFpREGie+Qh3gpnbig= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704931099; x=1705535899; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hRtOehh8h5mmIfnUBPPWvn4/oVyBLE/rm2Y8lVByjVU=; b=BwLNdAfhZmfM2bOmAyM0jtZ0ucrozoJP5RrhJqv8HuY/lNNnds2IzqQrtw+b6sQxgk HqxL5OKnXU82rB7ezlkkpleW5zOjonNcVdKcVYyLTLVL1MUfI7VTmD1jbXXxllPxDE/1 8w1xGCkdIMJGHeICaxyQVxPJ76QBHXeDeRVwo4MvsPZNfe07BrwnJgF15Qno0uVXBRhz inKdMvjlPsFfNznKO3247q8bPdqLn/2bYu5Tp1pzbODlDzaoem/ANqMEa9DVZkoWRrWe p58HOq+JWzq8M35lf/2ePxRUtcIsthws/EWwGYCuDxZCI6CsyoEvHyzdbXJHAuBL0glL k/Mg== X-Gm-Message-State: AOJu0YytMyEF1b7eb+FLq4IzsphUR2+VaAH/fGT1nHro6Br9JVmWjAwV 9hqNYLm7PR04dK8/lURKIUh/Glfapeu2 X-Received: by 2002:a17:903:24f:b0:1d4:47d4:82b4 with SMTP id j15-20020a170903024f00b001d447d482b4mr323485plh.15.1704931099623; Wed, 10 Jan 2024 15:58:19 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id jw17-20020a170903279100b001d0ca40158dsm4211771plb.280.2024.01.10.15.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 15:58:19 -0800 (PST) Date: Wed, 10 Jan 2024 15:58:18 -0800 From: Kees Cook To: "Lad, Prabhakar" Cc: Vinod Koul , Geert Uytterhoeven , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Tudor Ambarus , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , Lad Prabhakar Subject: Re: [PATCH] dmaengine: usb-dmac: Avoid format-overflow warning Message-ID: <202401101557.87634A6A@keescook> References: <20240110222210.193479-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <202401101437.48C52CF6@keescook> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Jan 10, 2024 at 10:46:02PM +0000, Lad, Prabhakar wrote: > Hi Kees, > > Thank you for the review. > > On Wed, Jan 10, 2024 at 10:41 PM Kees Cook wrote: > > > > On Wed, Jan 10, 2024 at 10:22:10PM +0000, Prabhakar wrote: > > > From: Lad Prabhakar > > > > > > gcc points out that the fix-byte buffer might be too small: > > > drivers/dma/sh/usb-dmac.c: In function 'usb_dmac_probe': > > > drivers/dma/sh/usb-dmac.c:720:34: warning: '%u' directive writing between 1 and 10 bytes into a region of size 3 [-Wformat-overflow=] > > > 720 | sprintf(pdev_irqname, "ch%u", index); > > > | ^~ > > > In function 'usb_dmac_chan_probe', > > > inlined from 'usb_dmac_probe' at drivers/dma/sh/usb-dmac.c:814:9: > > > drivers/dma/sh/usb-dmac.c:720:31: note: directive argument in the range [0, 4294967294] > > > 720 | sprintf(pdev_irqname, "ch%u", index); > > > | ^~~~~~ > > > drivers/dma/sh/usb-dmac.c:720:9: note: 'sprintf' output between 4 and 13 bytes into a destination of size 5 > > > 720 | sprintf(pdev_irqname, "ch%u", index); > > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > > > Maximum number of channels for USB-DMAC as per the driver is 1-99 so use > > > u8 instead of unsigned int/int for DMAC channel indexing and make the > > > pdev_irqname string long enough to avoid the warning. > > > > > > While at it use scnprintf() instead of sprintf() to make the code more > > > robust. > > > > > > Signed-off-by: Lad Prabhakar > > > > This looks like good fixes; thanks! I see n_channels is sanity checked > > during the probe in usb_dmac_chan_probe(), so this looks good. > > > > (Is there a reason not to also change n_channels to a u8?) > > > Good point, I oversighted it by just looking at the loop indices. I > will send a v2 with that change. I think you'll need a bounce variable in usb_dmac_chan_probe() since it looks like it's reading a 32-bit value from DT, but otherwise, it should be okay. -Kees -- Kees Cook