From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC021C43334 for ; Wed, 6 Jul 2022 10:43:00 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 0BB731695; Wed, 6 Jul 2022 12:42:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 0BB731695 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1657104179; bh=zrd7SJrYJgiBHyxXw1JHDeHv6/0QQpqh6HUxViDgkbY=; h=Date:Subject:To:References:From:In-Reply-To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XBC4MwWiF+hTgjAX+jypIhP5FnO6yqL287R5HCVlDPGEwzhTKQ0tAbWy/cldMTHAT yxxhiD+tx0D0mywvLe5PTF0uLSmK7QXkT+4HNdjxkC1oAprcpOOiiNG6xTcyNsgLMn UgkdlzznjCdbpSqcQbwKTWq/wZmYP1NimvMzh9bU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id AA85BF8016B; Wed, 6 Jul 2022 12:42:08 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E20EEF8023A; Wed, 6 Jul 2022 12:42:07 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 7A134F800C5; Wed, 6 Jul 2022 12:41:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 7A134F800C5 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="h4lY4tEQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657104125; x=1688640125; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=zrd7SJrYJgiBHyxXw1JHDeHv6/0QQpqh6HUxViDgkbY=; b=h4lY4tEQ2VGuMzdm7veZEvXRvKoM7nPvxwWf10ky/0p1ayYW40mcyldE ee9ThPTImACU7JAiGjQ/LIjAJTFDHMkWpumt0ExK5qb2/XSubS3OK1hBc ViROlennFLqHK6ICf+1ycAv0ey75jaX6TQC2BHU+KAv4LA7YB4oGI3109 mQoyLKd0jjW7l2HBFztTwZ0tDQtpGubmwZMi/O3p3PbT6F4Aj8dmbBg3h 64OWn+ccoMPlfWeJhVtuMqhTBIpcm0LAQuCxkrWbMn3sVJerGKtiTPnty xi3QNGT/3yHcfEoMFIEbWrgzDhIYadwkdoz1jvb2ZVEuBWQ8VZDrbwMSg Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="347693971" X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="347693971" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 03:41:02 -0700 X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="920113573" Received: from gguerra-mobl1.ger.corp.intel.com (HELO [10.249.254.46]) ([10.249.254.46]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 03:40:59 -0700 Message-ID: Date: Wed, 6 Jul 2022 13:41:45 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.10.0 Subject: Re: [PATCH 1/2] ASoC: SOF: sof-client-probes: fix error codes in sof_probes_compr_copy() Content-Language: en-US To: Dan Carpenter References: <26db7e60-51d1-444a-7620-8225239ad7bf@linux.intel.com> <20220706102159.GC2338@kadam> <20220706103139.GB2316@kadam> From: =?UTF-8?Q?P=c3=a9ter_Ujfalusi?= In-Reply-To: <20220706103139.GB2316@kadam> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: alsa-devel@alsa-project.org, Kai Vehmanen , Liam Girdwood , Bard Liao , Takashi Iwai , kernel-janitors@vger.kernel.org, Ranjani Sridharan , Pierre-Louis Bossart , Mark Brown , Daniel Baluta , sound-open-firmware@alsa-project.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On 06/07/2022 13:31, Dan Carpenter wrote: > 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); I think this should work, can you please resend it? > } > > +done: > if (ret) > return count - ret; > return count; -- Péter