public inbox for alsa-devel@alsa-project.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: "Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>
Cc: alsa-devel@alsa-project.org,
	Kai Vehmanen <kai.vehmanen@linux.intel.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Bard Liao <yung-chuan.liao@linux.intel.com>,
	Takashi Iwai <tiwai@suse.com>,
	kernel-janitors@vger.kernel.org,
	Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Mark Brown <broonie@kernel.org>,
	Daniel Baluta <daniel.baluta@nxp.com>,
	sound-open-firmware@alsa-project.org
Subject: Re: [PATCH 1/2] ASoC: SOF: sof-client-probes: fix error codes in sof_probes_compr_copy()
Date: Wed, 6 Jul 2022 13:31:39 +0300	[thread overview]
Message-ID: <20220706103139.GB2316@kadam> (raw)
In-Reply-To: <20220706102159.GC2338@kadam>

On Wed, Jul 06, 2022 at 01:21:59PM +0300, Dan Carpenter wrote:
> On Wed, Jul 06, 2022 at 12:05:37PM +0300, Péter Ujfalusi wrote:
> > 
> > 
> > On 06/07/2022 10:23, Dan Carpenter wrote:
> > > This function tries to return the number of bytes that it was able to
> > > copy to the user.  However, because there are multiple calls to
> > > copy_to_user() in a row that means the bytes are not necessarily
> > > consecutive so it's not useful.  Just return -EFAULT instead.
> > 
> > The function is copying data from a circular buffer to a use buffer.
> > The single copy_to_user() is used when we don't have wrapping, the
> > 'double' copy_to_user() is when we wrap, so first copy is from the end
> > of the buffer then we copy the data from the start of the buffer to get
> > all data.
> 
> Ok.  But the bugs in the original code are real.  I will resend.

Actually that's not true.  The bugs in the original code are something
that only affect users who deserve it?  I might not resend.  A fix would
look something like below?

regards,
dan carpenter

diff --git a/sound/soc/sof/sof-client-probes.c b/sound/soc/sof/sof-client-probes.c
index 1f1ea93a7fbf..32fa3186c295 100644
--- a/sound/soc/sof/sof-client-probes.c
+++ b/sound/soc/sof/sof-client-probes.c
@@ -398,9 +398,14 @@ static int sof_probes_compr_copy(struct snd_soc_component *component,
 		ret = copy_to_user(buf, ptr, count);
 	} else {
 		ret = copy_to_user(buf, ptr, n);
-		ret += copy_to_user(buf + n, rtd->dma_area, count - n);
+		if (ret) {
+			ret += count - n;
+			goto done;
+		}
+		ret = copy_to_user(buf + n, rtd->dma_area, count - n);
 	}
 
+done:
 	if (ret)
 		return count - ret;
 	return count;

  reply	other threads:[~2022-07-06 10:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-06  7:23 [PATCH 1/2] ASoC: SOF: sof-client-probes: fix error codes in sof_probes_compr_copy() Dan Carpenter
2022-07-06  7:25 ` [PATCH 2/2] ASoC: SOF: sof-client-probes: cleanup tokenize_input() Dan Carpenter
2022-07-06  9:27   ` Péter Ujfalusi
2022-07-06 10:44     ` Dan Carpenter
2022-07-06 10:56       ` Cezary Rojewski
2022-07-06  9:05 ` [PATCH 1/2] ASoC: SOF: sof-client-probes: fix error codes in sof_probes_compr_copy() Péter Ujfalusi
2022-07-06 10:00   ` Péter Ujfalusi
2022-07-06 10:21   ` Dan Carpenter
2022-07-06 10:31     ` Dan Carpenter [this message]
2022-07-06 10:36       ` Dan Carpenter
2022-07-06 10:41       ` Péter Ujfalusi

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=20220706103139.GB2316@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=daniel.baluta@nxp.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=sound-open-firmware@alsa-project.org \
    --cc=tiwai@suse.com \
    --cc=yung-chuan.liao@linux.intel.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