public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Brennan Lamoreaux <blamoreaux@vmware.com>
Cc: stable@vger.kernel.org, akaher@vmware.com, amakhalov@vmware.com,
	vsirnapalli@vmware.com, ankitja@vmware.com,
	Joe Perches <joe@perches.com>
Subject: Re: [PATCH v4.19.y] drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions
Date: Fri, 4 Aug 2023 12:22:09 +0200	[thread overview]
Message-ID: <2023080459-sprint-dreamless-eb79@gregkh> (raw)
In-Reply-To: <20230801213044.68581-1-blamoreaux@vmware.com>

On Tue, Aug 01, 2023 at 02:30:44PM -0700, Brennan Lamoreaux wrote:
> From: Joe Perches <joe@perches.com>
> 
> commit aa838896d87af561a33ecefea1caa4c15a68bc47 upstream
> 
> Convert the various sprintf fmaily calls in sysfs device show functions
> to sysfs_emit and sysfs_emit_at for PAGE_SIZE buffer safety.
> 
> Done with:
> 
> $ spatch -sp-file sysfs_emit_dev.cocci --in-place --max-width=80 .
> 
> And cocci script:
> 
> $ cat sysfs_emit_dev.cocci
> @@
> identifier d_show;
> identifier dev, attr, buf;
> @@
> 
> ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
> {
> 	<...
> 	return
> -	sprintf(buf,
> +	sysfs_emit(buf,
> 	...);
> 	...>
> }
> 
> @@
> identifier d_show;
> identifier dev, attr, buf;
> @@
> 
> ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
> {
> 	<...
> 	return
> -	snprintf(buf, PAGE_SIZE,
> +	sysfs_emit(buf,
> 	...);
> 	...>
> }
> 
> @@
> identifier d_show;
> identifier dev, attr, buf;
> @@
> 
> ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
> {
> 	<...
> 	return
> -	scnprintf(buf, PAGE_SIZE,
> +	sysfs_emit(buf,
> 	...);
> 	...>
> }
> 
> @@
> identifier d_show;
> identifier dev, attr, buf;
> expression chr;
> @@
> 
> ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
> {
> 	<...
> 	return
> -	strcpy(buf, chr);
> +	sysfs_emit(buf, chr);
> 	...>
> }
> 
> @@
> identifier d_show;
> identifier dev, attr, buf;
> identifier len;
> @@
> 
> ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
> {
> 	<...
> 	len =
> -	sprintf(buf,
> +	sysfs_emit(buf,
> 	...);
> 	...>
> 	return len;
> }
> 
> @@
> identifier d_show;
> identifier dev, attr, buf;
> identifier len;
> @@
> 
> ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
> {
> 	<...
> 	len =
> -	snprintf(buf, PAGE_SIZE,
> +	sysfs_emit(buf,
> 	...);
> 	...>
> 	return len;
> }
> 
> @@
> identifier d_show;
> identifier dev, attr, buf;
> identifier len;
> @@
> 
> ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
> {
> 	<...
> 	len =
> -	scnprintf(buf, PAGE_SIZE,
> +	sysfs_emit(buf,
> 	...);
> 	...>
> 	return len;
> }
> 
> @@
> identifier d_show;
> identifier dev, attr, buf;
> identifier len;
> @@
> 
> ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
> {
> 	<...
> -	len += scnprintf(buf + len, PAGE_SIZE - len,
> +	len += sysfs_emit_at(buf, len,
> 	...);
> 	...>
> 	return len;
> }
> 
> @@
> identifier d_show;
> identifier dev, attr, buf;
> expression chr;
> @@
> 
> ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
> {
> 	...
> -	strcpy(buf, chr);
> -	return strlen(buf);
> +	return sysfs_emit(buf, chr);
> }
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> Link: https://lore.kernel.org/r/3d033c33056d88bbe34d4ddb62afd05ee166ab9a.1600285923.git.joe@perches.com
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> [ Brennan : Regenerated for 4.19 to fix CVE-2022-20166 ]
> Signed-off-by: Brennan Lamoreaux <blamoreaux@vmware.com>

Thanks, now queued up.

greg k-h

  reply	other threads:[~2023-08-04 10:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01 19:52 [PATCH v4.19.y] drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions Brennan Lamoreaux
2023-08-01 21:23 ` Brennan Lamoreaux
2023-08-01 21:30   ` Brennan Lamoreaux
2023-08-04 10:22     ` Greg Kroah-Hartman [this message]
2023-08-04 10:29       ` Greg Kroah-Hartman
2023-08-04 10:41         ` Greg Kroah-Hartman
2023-08-04 17:20           ` Brennan Lamoreaux
2023-08-07 17:02             ` Brennan Lamoreaux

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2023080459-sprint-dreamless-eb79@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=akaher@vmware.com \
    --cc=amakhalov@vmware.com \
    --cc=ankitja@vmware.com \
    --cc=blamoreaux@vmware.com \
    --cc=joe@perches.com \
    --cc=stable@vger.kernel.org \
    --cc=vsirnapalli@vmware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox