alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Vinod Koul <vinod.koul@intel.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: liam.r.girdwood@linux.intel.com, patches.audio@intel.com,
	alsa-devel@alsa-project.org, broonie@kernel.org
Subject: Re: [PATCH] amixer: add support for TLV byte control read
Date: Fri, 22 Jan 2016 15:26:48 +0530	[thread overview]
Message-ID: <20160122095648.GD11130@localhost> (raw)
In-Reply-To: <s5hfuxq593q.wl-tiwai@suse.de>

On Fri, Jan 22, 2016 at 09:09:13AM +0100, Takashi Iwai wrote:
> On Fri, 22 Jan 2016 08:46:23 +0100,
> Vinod Koul wrote:
> > 
> > On Fri, Jan 22, 2016 at 07:19:10AM +0100, Takashi Iwai wrote:
> > > On Fri, 22 Jan 2016 06:46:52 +0100,
> > > Vinod Koul wrote:
> > > > 
> > > > TLV byte control are new type of byte controls added in kernel where
> > > > controls can have large sizes.
> > > >
> > > > For these controls querying with 4096 size fails, so use the queried size to
> > > > read the control
> > > > 
> > > > This fixes the crash with current cget/contents on these type of controls
> > > 
> > > Hmm...  Theoretically the TLV size and the element size are
> > > independent.  So, it's not good to check only the type being
> > > SND_CTL_ELEM_TYPE_BYTES.  This can be used legally by other cases,
> > > too.
> > > 
> > > Basically it is an abuse in ASoC side to return the size of
> > > TLV by the element's info.  Usually such value would lead to crash,
> > > but the unique point of ASoC ext bytes ctl is that it doesn't have RW
> > > accesses but only TLV_RW accesses.
> > 
> > But isn't that already checked? Since we are in the code which will be
> > executed only for tlv as snd_ctl_elem_info_is_tlv_readable() ensures that.
> > So this is only for tlv + bytes ...
> 
> I meant setting a bogus count value in info would usually lead to a
> crash.  The point isn't about TLV access.
> 
> > > So, instead of only checking the type being BYTES, check the
> > > accesses.  Only when all these conditions are met, we may take the
> > > count as TLV (element) size.  (And still we should have the sanity
> > > check of the value, too.)
> > > 
> > > Yet, this isn't a really "fix" for the crash.  Even without the patch
> > > it shouldn't crash -- it should receive 4096 bytes, and tries to
> > > decode.  Where did you get the crash exactly?
> > 
> > in alsa-lib snd_ctl_hw_elem_tlv() when it tries to do memcpy for tlv read.
> > But the crash is caused as tlv read is large and we have only 4096 size
> > buffer,
> 
> Hm, it has a check
> 
> static int snd_ctl_hw_elem_tlv(snd_ctl_t *handle, int op_flag,
> 			       unsigned int numid,
> 			       unsigned int *tlv, unsigned int tlv_size)
> {
> 	....
> 		if (xtlv->tlv[1] + 2 * sizeof(unsigned int) > tlv_size) {
> 			free(xtlv);
> 			return -EFAULT;
> 		}
> 		memcpy(tlv, xtlv->tlv, xtlv->tlv[1] + 2 * sizeof(unsigned int));
> 
> Do you mean somewhere here triggers a crash?

Yes while it tried to memcpy, in my case 30K sized data to 4K buffer, so I
allocated right one and got all the data

> 
> > so we ensure we give right size buffer here
> 
> Actually we should have an API function that returns the size of TLV.
> Then amixer can adjust the allocation size.

Yes we can add tat too. I want to make coontents and cget work okay while I
add proper TLV support. Maybe we should stop cget on tlv byte type?

-- 
~Vinod

  parent reply	other threads:[~2016-01-22  9:53 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-22  5:46 [PATCH] amixer: add support for TLV byte control read Vinod Koul
2016-01-22  6:19 ` Takashi Iwai
2016-01-22  7:46   ` Vinod Koul
2016-01-22  8:09     ` Takashi Iwai
2016-01-22  8:26       ` Takashi Iwai
2016-01-22  9:57         ` Vinod Koul
2016-01-22  9:56       ` Vinod Koul [this message]
2016-01-22 10:50         ` Takashi Iwai
2016-01-27 17:47           ` Vinod Koul
2016-01-27 18:49             ` Takashi Iwai
2016-01-28  4:25               ` Vinod Koul
2016-01-28  5:49                 ` Takashi Iwai
2016-01-28  9:26                   ` Vinod Koul
2016-01-28 16:19                     ` Takashi Iwai
2016-01-29  6:51                       ` Vinod Koul
2016-01-29 11:13                         ` Vinod Koul
2016-01-29 13:17                           ` Takashi Iwai
2016-01-29 13:53                             ` Vinod Koul
2016-01-29 13:53                               ` Takashi Iwai

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=20160122095648.GD11130@localhost \
    --to=vinod.koul@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=patches.audio@intel.com \
    --cc=tiwai@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).