Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3124328pxv; Mon, 12 Jul 2021 09:50:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6+z5y9ZuiNq+StGRNJkX9O8RMGJUthRELB0ZGleisA7zFIOlXo6jhpEHP3cZOynE9UEC7 X-Received: by 2002:a05:6402:10c7:: with SMTP id p7mr49297997edu.159.1626108623760; Mon, 12 Jul 2021 09:50:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626108623; cv=none; d=google.com; s=arc-20160816; b=nY5nFANBlSDNa2pnPscgedAPrigyjd2hYMW2FYa/SUZ0rUuITykhgslwCzD36q8m6g iYCmcXFDZaM3nshM4gf3+9DJnOvvkk1l/3mFW4YuErjbacco5pQzZBKnYqNoZkFrxzxX 0NFMvGo/JYC50vwNShcQp2gIV7TMcGqHSSVLKL4+xiVV4w1JGYK14RE8pJ1LcZfy1R++ G4xupJZL2mzB9QAgA7GyGh+JS0wdf2PRRUHrdmdQcbmNFRRAyUi6dxdVILWu70tG+4im 8NN9XhxZaxD3FzlxVCXRVv/7wVkb5dzTmTFiX7jo7qDxVEDqYahRlM1sTEdGN1ua9HVW lTGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=vrlH/BEa1Ukur1S/mi+PlZ4jOc9+GaUY7xVMMWuoOpw=; b=dHAhCN35ibMrCL+q26BougTJTqOSOnwhPNRN4IGPFrFfrZxT3YYEYUG6fn8esDKifs GGD07IzViiC8PXSZ0kyvnrORrTtAkPmYScG+zWrwUeQ618iYK1nUjd0CrCcLeNn6jh96 fejS7tg6vsD3at22RejYvlehotdP/cQjU5BOYc/5PHC08pAhpX5vdVXEvHuXmgcbITzo g9ZBn8hzJ0PB3wmlCGVUpdvzGyEw0ZlJdDtz4HV0LA2OjGYWi7YNcN44l6dYTBa3avPY QUfscgUhIUhfXyRF9fq7GeAs8MW/jX/gXnfjTBGVESzN9C3FmfpUwj29BdJEGTayoHsL RAVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=J4Qr591c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rh9si15515624ejb.651.2021.07.12.09.50.00; Mon, 12 Jul 2021 09:50:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=J4Qr591c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233869AbhGLQvp (ORCPT + 99 others); Mon, 12 Jul 2021 12:51:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232710AbhGLQvo (ORCPT ); Mon, 12 Jul 2021 12:51:44 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19E0BC0613DD for ; Mon, 12 Jul 2021 09:48:55 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id ga14so20864140ejc.6 for ; Mon, 12 Jul 2021 09:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=vrlH/BEa1Ukur1S/mi+PlZ4jOc9+GaUY7xVMMWuoOpw=; b=J4Qr591cps0wLoXsvoIBsp3jSfBfxcfDwErbT1PuZNYjwNiimAx672mA29WP/OhGDz Q63+87vRFvTywbx1Lj8RLwULv+xQKH7NjidircbWHgyi/XdnHRc2nDSfExHxGbwHqmCu RRkwOP4Oqf+OACU4VjVn1F/o0zizlB5FGS5aVAd5EV1zYa1CRx8ogvykHWo57W/721CA OzsYWUK5/cK28Wc3MfCxscG7QeWE6/DawTRxw0mkxN2d5WmgcUvQXYh9YXsxDb9P7q1O hwKssMpouyS3JtHNYLILnFc4sXWv1aTqIbbZIBlNy7L7fdk/4Gl7ljWKHOZ1u8+FWX9b ukyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=vrlH/BEa1Ukur1S/mi+PlZ4jOc9+GaUY7xVMMWuoOpw=; b=hQaG1yM7HhRoQy7o7/2+MwcwvqTOAqHT5JGJuJte1KQl61jQKdIxEsA4XUd/G4uqWe ZG/lW+LOetojGE3hfwRurULFlVb+3L73unQ/42F0abGF+c9cFJOOP9td+fhLMg1eH/f+ UOOHID1qraY4UICnZp7kOOti5m4Ek28r1OsQOvJJiih9neNBIfa7PHBtKjBp//E5Izsp BJjNwKzfTQpiBrMWmqKDHTajrcnRBDK205dN3xMFjSs+sBJlVch9yBoVmfdnriwsYfVW 4ZFtzuPUsMWbYmLtcssGtWnMPC1ct6bMZ/6VNvM5CVB8LC2s3BzBQcr3QzDVQg4TdXya Bdxw== X-Gm-Message-State: AOAM531vpT+rp+4HJBj8QZ8OQuZEyoDPLwk2POTG6mzdU3grYdK2fF6g qNC9BSPMGSBYZrUYhaMLqJA= X-Received: by 2002:a17:907:72ce:: with SMTP id du14mr53915938ejc.529.1626108533604; Mon, 12 Jul 2021 09:48:53 -0700 (PDT) Received: from pc ([196.235.212.194]) by smtp.gmail.com with ESMTPSA id v13sm8815519edl.47.2021.07.12.09.48.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 09:48:53 -0700 (PDT) Date: Mon, 12 Jul 2021 17:48:50 +0100 From: Salah Triki To: Joe Perches Cc: dan.j.williams@intel.com, vishal.l.verma@intel.com, dave.jiang@intel.com, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] dax: replace sprintf() by scnprintf() Message-ID: <20210712164850.GC777994@pc> References: <20210710164615.GA690067@pc> <10621e048f62018432c42a3fccc1a5fd9a6d71d7.camel@perches.com> <20210712122624.GB777994@pc> <6fe3c15d985017ad4e7a266bcf214a711326f151.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6fe3c15d985017ad4e7a266bcf214a711326f151.camel@perches.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 12, 2021 at 09:14:53AM -0700, Joe Perches wrote: > On Mon, 2021-07-12 at 13:26 +0100, Salah Triki wrote: > > On Sat, Jul 10, 2021 at 10:04:48AM -0700, Joe Perches wrote: > > > On Sat, 2021-07-10 at 17:46 +0100, Salah Triki wrote: > > > > Replace sprintf() by scnprintf() in order to avoid buffer overflows. > > > > > > OK but also not strictly necessary. DAX_NAME_LEN is 30. > > > > > > Are you finding and changing these manually or with a script? > > > > > > > diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c > > > [] > > > > @@ -76,7 +76,7 @@ static ssize_t do_id_store(struct device_driver *drv, const char *buf, > > > > ? fields = sscanf(buf, "dax%d.%d", ®ion_id, &id); > > > > ? if (fields != 2) > > > > ? return -EINVAL; > > > > - sprintf(devname, "dax%d.%d", region_id, id); > > > > + scnprintf(devname, DAX_NAME_LEN, "dax%d.%d", region_id, id); > > > > ? if (!sysfs_streq(buf, devname)) > > > > ? return -EINVAL; > > > > ? > > > > > > > > > > > > > > since region_id and id are unsigned long may be devname should be > > char[21]. > > I think you need to look at the code a bit more carefully. > > unsigned int region_id, id; > > Also the output is %d, so the maximum length of each output > int is 10 with a possible leading minus sign. > > 3 + 10 + 1 + 10 + 1. So 25 not 21 which is too small. > > The %d uses could be changed to %u to make it 23. > But really it hardly matters as 30 is sufficent and the > function call depth here isn't particularly high. > > > I'm finding and changing these manually. > > coccinelle could help. > https://coccinelle.gitlabpages.inria.fr/website/ > > Thanx