* [PATCH] hda: add bounds checking for the codec command fields @ 2009-07-17 8:24 Wu Fengguang 2009-07-17 8:27 ` Wu Fengguang 0 siblings, 1 reply; 8+ messages in thread From: Wu Fengguang @ 2009-07-17 8:24 UTC (permalink / raw) To: alsa-devel; +Cc: Takashi Iwai, Chaohong Guo A recent bug involves passing auto detected >0x7f NID to codec command, creating an invalid codec addr field, and finally lead to cmd timeout and fall back into single command mode. Jaroslav fixed that bug in alc880_parse_auto_config(). It would be safer to further check the bounds of all cmd fields. Cc: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> --- diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 462e2ce..7d09650 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -150,6 +150,16 @@ make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct, { u32 val; + if ((direct & ~1) || (nid & ~0x7f) || + (verb & ~0xfff) || (parm & ~0xff)) { + printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n", + codec->addr, direct, nid, verb, parm); + direct &= 1; + nid &= 0x7f; + verb &= 0xfff; + parm &= 0xff; + } + val = (u32)(codec->addr & 0x0f) << 28; val |= (u32)direct << 27; val |= (u32)nid << 20; ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] hda: add bounds checking for the codec command fields 2009-07-17 8:24 [PATCH] hda: add bounds checking for the codec command fields Wu Fengguang @ 2009-07-17 8:27 ` Wu Fengguang 2009-07-17 8:49 ` [PATCH] hda: add bounds checking for the codec command fields v2 Wu Fengguang 0 siblings, 1 reply; 8+ messages in thread From: Wu Fengguang @ 2009-07-17 8:27 UTC (permalink / raw) To: alsa-devel; +Cc: Takashi Iwai, Chaohong Guo On Fri, Jul 17, 2009 at 04:24:10PM +0800, Wu Fengguang wrote: > A recent bug involves passing auto detected >0x7f NID to codec command, > creating an invalid codec addr field, and finally lead to cmd timeout > and fall back into single command mode. Jaroslav fixed that bug in > alc880_parse_auto_config(). > > It would be safer to further check the bounds of all cmd fields. > > Cc: Jaroslav Kysela <perex@perex.cz> > Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> > --- > diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c > index 462e2ce..7d09650 100644 > --- a/sound/pci/hda/hda_codec.c > +++ b/sound/pci/hda/hda_codec.c > @@ -150,6 +150,16 @@ make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct, > { > u32 val; > > + if ((direct & ~1) || (nid & ~0x7f) || > + (verb & ~0xfff) || (parm & ~0xff)) { > + printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n", > + codec->addr, direct, nid, verb, parm); Maybe we shall simply return here? > + direct &= 1; > + nid &= 0x7f; > + verb &= 0xfff; > + parm &= 0xff; > + } > + > val = (u32)(codec->addr & 0x0f) << 28; > val |= (u32)direct << 27; > val |= (u32)nid << 20; ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] hda: add bounds checking for the codec command fields v2 2009-07-17 8:27 ` Wu Fengguang @ 2009-07-17 8:49 ` Wu Fengguang 2009-07-17 9:28 ` Takashi Iwai [not found] ` <BB1F052FCDB1EA468BD99786C8B1ED2C05871FFCB9@PDSMSX501.ccr.corp.intel.com> 0 siblings, 2 replies; 8+ messages in thread From: Wu Fengguang @ 2009-07-17 8:49 UTC (permalink / raw) To: alsa-devel; +Cc: Takashi Iwai, Chaohong Guo, John Villalovos On Fri, Jul 17, 2009 at 04:27:03PM +0800, Wu Fengguang wrote: > On Fri, Jul 17, 2009 at 04:24:10PM +0800, Wu Fengguang wrote: > > A recent bug involves passing auto detected >0x7f NID to codec command, > > creating an invalid codec addr field, and finally lead to cmd timeout > > and fall back into single command mode. Jaroslav fixed that bug in > > alc880_parse_auto_config(). > > > > It would be safer to further check the bounds of all cmd fields. > > > > Cc: Jaroslav Kysela <perex@perex.cz> > > Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> > > --- > > diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c > > index 462e2ce..7d09650 100644 > > --- a/sound/pci/hda/hda_codec.c > > +++ b/sound/pci/hda/hda_codec.c > > @@ -150,6 +150,16 @@ make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct, > > { > > u32 val; > > > > + if ((direct & ~1) || (nid & ~0x7f) || > > + (verb & ~0xfff) || (parm & ~0xff)) { > > + printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n", > > + codec->addr, direct, nid, verb, parm); > > Maybe we shall simply return here? Here it is :) --- hda: add bounds checking for the codec command fields A recent bug involves passing auto detected >0x7f NID to codec command, creating an invalid codec addr field, and finally lead to cmd timeout and fall back into single command mode. Jaroslav fixed that bug in alc880_parse_auto_config(). It would be safer to further check the bounds of all cmd fields. Cc: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> --- sound/pci/hda/hda_codec.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- sound-2.6.orig/sound/pci/hda/hda_codec.c +++ sound-2.6/sound/pci/hda/hda_codec.c @@ -150,7 +150,14 @@ make_codec_cmd(struct hda_codec *codec, { u32 val; - val = (u32)(codec->addr & 0x0f) << 28; + if ((codec->addr & ~0xf) | (direct & ~1) | (nid & ~0x7f) | + (verb & ~0xfff) | (parm & ~0xff)) { + printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n", + codec->addr, direct, nid, verb, parm); + return ~0; + } + + val = (u32)codec->addr << 28; val |= (u32)direct << 27; val |= (u32)nid << 20; val |= verb << 8; @@ -167,6 +174,9 @@ static int codec_exec_verb(struct hda_co struct hda_bus *bus = codec->bus; int err; + if (cmd == ~0) + return -1; + if (res) *res = -1; again: ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] hda: add bounds checking for the codec command fields v2 2009-07-17 8:49 ` [PATCH] hda: add bounds checking for the codec command fields v2 Wu Fengguang @ 2009-07-17 9:28 ` Takashi Iwai [not found] ` <BB1F052FCDB1EA468BD99786C8B1ED2C05871FFCB9@PDSMSX501.ccr.corp.intel.com> 1 sibling, 0 replies; 8+ messages in thread From: Takashi Iwai @ 2009-07-17 9:28 UTC (permalink / raw) To: Wu Fengguang; +Cc: Chaohong Guo, alsa-devel, John Villalovos At Fri, 17 Jul 2009 16:49:19 +0800, Wu Fengguang wrote: > > On Fri, Jul 17, 2009 at 04:27:03PM +0800, Wu Fengguang wrote: > > On Fri, Jul 17, 2009 at 04:24:10PM +0800, Wu Fengguang wrote: > > > A recent bug involves passing auto detected >0x7f NID to codec command, > > > creating an invalid codec addr field, and finally lead to cmd timeout > > > and fall back into single command mode. Jaroslav fixed that bug in > > > alc880_parse_auto_config(). > > > > > > It would be safer to further check the bounds of all cmd fields. > > > > > > Cc: Jaroslav Kysela <perex@perex.cz> > > > Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> > > > --- > > > diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c > > > index 462e2ce..7d09650 100644 > > > --- a/sound/pci/hda/hda_codec.c > > > +++ b/sound/pci/hda/hda_codec.c > > > @@ -150,6 +150,16 @@ make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct, > > > { > > > u32 val; > > > > > > + if ((direct & ~1) || (nid & ~0x7f) || > > > + (verb & ~0xfff) || (parm & ~0xff)) { > > > + printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n", > > > + codec->addr, direct, nid, verb, parm); > > > > Maybe we shall simply return here? > > Here it is :) > > --- > hda: add bounds checking for the codec command fields > > A recent bug involves passing auto detected >0x7f NID to codec command, > creating an invalid codec addr field, and finally lead to cmd timeout > and fall back into single command mode. Jaroslav fixed that bug in > alc880_parse_auto_config(). > > It would be safer to further check the bounds of all cmd fields. > > Cc: Jaroslav Kysela <perex@perex.cz> > Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> Looks good. Applied now. Thanks! Takashi > --- > sound/pci/hda/hda_codec.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > --- sound-2.6.orig/sound/pci/hda/hda_codec.c > +++ sound-2.6/sound/pci/hda/hda_codec.c > @@ -150,7 +150,14 @@ make_codec_cmd(struct hda_codec *codec, > { > u32 val; > > - val = (u32)(codec->addr & 0x0f) << 28; > + if ((codec->addr & ~0xf) | (direct & ~1) | (nid & ~0x7f) | > + (verb & ~0xfff) | (parm & ~0xff)) { > + printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n", > + codec->addr, direct, nid, verb, parm); > + return ~0; > + } > + > + val = (u32)codec->addr << 28; > val |= (u32)direct << 27; > val |= (u32)nid << 20; > val |= verb << 8; > @@ -167,6 +174,9 @@ static int codec_exec_verb(struct hda_co > struct hda_bus *bus = codec->bus; > int err; > > + if (cmd == ~0) > + return -1; > + > if (res) > *res = -1; > again: > ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <BB1F052FCDB1EA468BD99786C8B1ED2C05871FFCB9@PDSMSX501.ccr.corp.intel.com>]
[parent not found: <s5hljmn8u52.wl%tiwai@suse.de>]
* Re: [PATCH] hda: add bounds checking for the codec command fields v2 [not found] ` <s5hljmn8u52.wl%tiwai@suse.de> @ 2009-07-17 10:53 ` Takashi Iwai 2009-07-17 11:10 ` Wu Fengguang 2009-07-17 11:05 ` Wu Fengguang 1 sibling, 1 reply; 8+ messages in thread From: Takashi Iwai @ 2009-07-17 10:53 UTC (permalink / raw) To: Wu, Fengguang; +Cc: Guo, Chaohong, alsa-devel@alsa-project.org, John Villalovos At Fri, 17 Jul 2009 12:46:01 +0200, I wrote: > > At Fri, 17 Jul 2009 18:41:05 +0800, > Guo, Chaohong wrote: > > > > Although it does address this issue, I am not comfortable with this fixing. > > It seems more like a workaround than fix. > > No, it's rather for catching a bug. This is definitely neither > "workaround" nor "fix". BTW, I fixed the patch again as below. Takashi --- >From 82e1b804b03defe46fb69ffd2c8b19e6649bcb0d Mon Sep 17 00:00:00 2001 From: Takashi Iwai <tiwai@suse.de> Date: Fri, 17 Jul 2009 12:47:34 +0200 Subject: [PATCH] ALSA: hda - Fix the previous sanity check in make_codec_cmd() The newly added sanity-check for a codec verb can be better written with logical ORs. Also, the parameter can be more than 8bit. Signed-off-by: Takashi Iwai <tiwai@suse.de> --- sound/pci/hda/hda_codec.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index d9d3262..35f0f22 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -150,8 +150,8 @@ make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct, { u32 val; - if ((codec->addr & ~0xf) | (direct & ~1) | (nid & ~0x7f) | - (verb & ~0xfff) | (parm & ~0xff)) { + if ((codec->addr & ~0xf) || (direct & ~1) || (nid & ~0x7f) || + (verb & ~0xfff) || (parm & ~0xffff)) { printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n", codec->addr, direct, nid, verb, parm); return ~0; -- 1.6.3.2 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] hda: add bounds checking for the codec command fields v2 2009-07-17 10:53 ` Takashi Iwai @ 2009-07-17 11:10 ` Wu Fengguang 0 siblings, 0 replies; 8+ messages in thread From: Wu Fengguang @ 2009-07-17 11:10 UTC (permalink / raw) To: Takashi Iwai; +Cc: Guo, Chaohong, alsa-devel@alsa-project.org, John Villalovos On Fri, Jul 17, 2009 at 06:53:24PM +0800, Takashi Iwai wrote: > At Fri, 17 Jul 2009 12:46:01 +0200, > I wrote: > > > > At Fri, 17 Jul 2009 18:41:05 +0800, > > Guo, Chaohong wrote: > > > > > > Although it does address this issue, I am not comfortable with this fixing. > > > It seems more like a workaround than fix. > > > > No, it's rather for catching a bug. This is definitely neither > > "workaround" nor "fix". > > BTW, I fixed the patch again as below. > > > Takashi > > --- > >From 82e1b804b03defe46fb69ffd2c8b19e6649bcb0d Mon Sep 17 00:00:00 2001 > From: Takashi Iwai <tiwai@suse.de> > Date: Fri, 17 Jul 2009 12:47:34 +0200 > Subject: [PATCH] ALSA: hda - Fix the previous sanity check in make_codec_cmd() > > The newly added sanity-check for a codec verb can be better written > with logical ORs. Also, the parameter can be more than 8bit. Ah OK, thanks for the fix! Thanks, Fengguang ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] hda: add bounds checking for the codec command fields v2 [not found] ` <s5hljmn8u52.wl%tiwai@suse.de> 2009-07-17 10:53 ` Takashi Iwai @ 2009-07-17 11:05 ` Wu Fengguang 2009-07-20 2:13 ` Guo, Chaohong 1 sibling, 1 reply; 8+ messages in thread From: Wu Fengguang @ 2009-07-17 11:05 UTC (permalink / raw) To: Takashi Iwai; +Cc: Guo, Chaohong, alsa-devel@alsa-project.org, John Villalovos On Fri, Jul 17, 2009 at 06:46:01PM +0800, Takashi Iwai wrote: > At Fri, 17 Jul 2009 18:41:05 +0800, > Guo, Chaohong wrote: > > > > Although it does address this issue, I am not comfortable with this fixing. > > It seems more like a workaround than fix. > > No, it's rather for catching a bug. This is definitely neither > "workaround" nor "fix". Yes, I wrote this mainly for catching unknown bugs. > > Moreover, if long format node > > ID is used in the future, the code will cause little trouble for maintaining. > > Well, the current code doesn't support the long id (as the restriction > of HD-audio controller side), so we'd need major changes in anyway. > Thus this check is no big issue for maintenance, at least to me :) Does the HDA spec define cmd format that accept long form NID? If so, can you point me to the specific location please? Thanks. > > what I want is to fix it during parsing connection list, and verify the node > > id is valid there . > > Heh, this was already fixed :) AFAIK, snd_hda_get_connections() won't return NIDs bigger than 0x7f(short) or 0x7ffff(long). Thanks, Fengguang ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] hda: add bounds checking for the codec command fields v2 2009-07-17 11:05 ` Wu Fengguang @ 2009-07-20 2:13 ` Guo, Chaohong 0 siblings, 0 replies; 8+ messages in thread From: Guo, Chaohong @ 2009-07-20 2:13 UTC (permalink / raw) To: Wu, Fengguang, Takashi Iwai Cc: alsa-devel@alsa-project.org, John Villalovos, Jaroslav >Cc: Guo, Chaohong; alsa-devel@alsa-project.org; Jaroslav >Kysela; John Villalovos >Subject: Re: [PATCH] hda: add bounds checking for the codec >command fields v2 > >On Fri, Jul 17, 2009 at 06:46:01PM +0800, Takashi Iwai wrote: >> At Fri, 17 Jul 2009 18:41:05 +0800, >> Guo, Chaohong wrote: >> > >> > Although it does address this issue, I am not comfortable >with this fixing. >> > It seems more like a workaround than fix. >> >> No, it's rather for catching a bug. This is definitely neither >> "workaround" nor "fix". > >Yes, I wrote this mainly for catching unknown bugs. Oh, I misunderstood your intention. So, we still need to investigate the bug which occurs on RH i386 version :) > >> > Moreover, if long format node >> > ID is used in the future, the code will cause little >trouble for maintaining. >> >> Well, the current code doesn't support the long id (as the >restriction >> of HD-audio controller side), so we'd need major changes in anyway. >> Thus this check is no big issue for maintenance, at least to me :) > >Does the HDA spec define cmd format that accept long form NID? >If so, can you point me to the specific location please? Thanks. No. AFAIK, HDA doesn't specifiy long NID verb yet, I said "In the feature". but who knows why hardware vendors want to use long NID in the future, seems 128 is enough. -minskey > >> > what I want is to fix it during parsing connection list, >and verify the node >> > id is valid there . >> >> Heh, this was already fixed :) > >AFAIK, snd_hda_get_connections() won't return NIDs bigger than >0x7f(short) or 0x7ffff(long). > >Thanks, >Fengguang > ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-07-20 2:15 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-17 8:24 [PATCH] hda: add bounds checking for the codec command fields Wu Fengguang
2009-07-17 8:27 ` Wu Fengguang
2009-07-17 8:49 ` [PATCH] hda: add bounds checking for the codec command fields v2 Wu Fengguang
2009-07-17 9:28 ` Takashi Iwai
[not found] ` <BB1F052FCDB1EA468BD99786C8B1ED2C05871FFCB9@PDSMSX501.ccr.corp.intel.com>
[not found] ` <s5hljmn8u52.wl%tiwai@suse.de>
2009-07-17 10:53 ` Takashi Iwai
2009-07-17 11:10 ` Wu Fengguang
2009-07-17 11:05 ` Wu Fengguang
2009-07-20 2:13 ` Guo, Chaohong
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.