All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Ryder Lee <Ryder.Lee@mediatek.com>
Cc: "Shayne Chen (陳軒丞)" <Shayne.Chen@mediatek.com>,
	"StanleyYP Wang (王侑邦)" <StanleyYP.Wang@mediatek.com>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Howard-YH Hsu (許育豪)" <Howard-YH.Hsu@mediatek.com>,
	"gustavo@embeddedor.com" <gustavo@embeddedor.com>,
	"Evelyn Tsai (蔡珊鈺)" <Evelyn.Tsai@mediatek.com>,
	"Money Wang (王信安)" <Money.Wang@mediatek.com>,
	"linux-hardening@vger.kernel.org"
	<linux-hardening@vger.kernel.org>, "nbd@nbd.name" <nbd@nbd.name>,
	"MeiChia Chiu (邱美嘉)" <MeiChia.Chiu@mediatek.com>,
	"lorenzo@kernel.org" <lorenzo@kernel.org>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"Sean Wang" <Sean.Wang@mediatek.com>,
	"kvalo@kernel.org" <kvalo@kernel.org>,
	"edumazet@google.com" <edumazet@google.com>,
	"Sujuan Chen (陈素娟)" <Sujuan.Chen@mediatek.com>,
	"Chui-hao Chiu (邱垂浩)" <Chui-hao.Chiu@mediatek.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"linux-next@vger.kernel.org" <linux-next@vger.kernel.org>,
	"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
	"Bo Jiao (焦波)" <Bo.Jiao@mediatek.com>
Subject: Re: Coverity: mt7996_hw_queue_read(): Integer handling issues
Date: Tue, 6 Dec 2022 15:37:05 -0800	[thread overview]
Message-ID: <202212061535.5D3DA489FB@keescook> (raw)
In-Reply-To: <786eff1a1751a5bc0dc68d6567be585b635bddb1.camel@mediatek.com>

On Sat, Dec 03, 2022 at 04:40:09AM +0000, Ryder Lee wrote:
> On Fri, 2022-12-02 at 14:11 -0800, coverity-bot wrote:
> > Hello!
> > 
> > This is an experimental semi-automated report about issues detected
> > by
> > Coverity from a scan of next-20221202 as part of the linux-next scan
> > project:
> > 
> https://urldefense.com/v3/__https://scan.coverity.com/projects/linux-next-weekly-scan__;!!CTRNKA9wMg0ARbw!jBOoj6LMqqA8E0AyjKQTa-0rVzcFiZ3BbpciEIn7so974kcMBeG4zZm-QU4AudLXY7-jNUSt0unzAt2zirSF$ 
> >  
> > 
> > You're getting this email because you were associated with the
> > identified
> > lines of code (noted below) that were touched by commits:
> > 
> >   Thu Dec 1 17:29:14 2022 +0100
> >     98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi
> > 7 (802.11be) devices")
> > 
> > Coverity reported the following:
> > 
> > *** CID 1527813:  Integer handling issues  (SIGN_EXTENSION)
> > drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c:460 in
> > mt7996_hw_queue_read()
> > 454     	for (i = 0; i < size; i++) {
> > 455     		u32 ctrl, head, tail, queued;
> > 456
> > 457     		if (val & BIT(map[i].index))
> > 458     			continue;
> > 459
> > vvv     CID 1527813:  Integer handling issues  (SIGN_EXTENSION)
> > vvv     Suspicious implicit sign extension: "map[i].qid" with type
> > "u8" (8 bits, unsigned) is promoted in "map[i].qid << 24" to type
> > "int" (32 bits, signed), then sign-extended to type "unsigned long"
> > (64 bits, unsigned).  If "map[i].qid << 24" is greater than
> > 0x7FFFFFFF, the upper bits of the result will all be 1.
> > 460     		ctrl = BIT(31) | (map[i].pid << 10) |
> > (map[i].qid << 24);
> 
> u32 ctrl = BIT(31) | (map[i].pid << 10) | (map[i].qid << 24);
> 
> Hmm ...where's type "int" (32 bits, signed) from?

	map[i].qid is promoted to int before the "<< 24".

-- 
Kees Cook

WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org>
To: Ryder Lee <Ryder.Lee@mediatek.com>
Cc: "Shayne Chen (陳軒丞)" <Shayne.Chen@mediatek.com>,
	"StanleyYP Wang (王侑邦)" <StanleyYP.Wang@mediatek.com>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Howard-YH Hsu (許育豪)" <Howard-YH.Hsu@mediatek.com>,
	"gustavo@embeddedor.com" <gustavo@embeddedor.com>,
	"Evelyn Tsai (蔡珊鈺)" <Evelyn.Tsai@mediatek.com>,
	"Money Wang (王信安)" <Money.Wang@mediatek.com>,
	"linux-hardening@vger.kernel.org"
	<linux-hardening@vger.kernel.org>, "nbd@nbd.name" <nbd@nbd.name>,
	"MeiChia Chiu (邱美嘉)" <MeiChia.Chiu@mediatek.com>,
	"lorenzo@kernel.org" <lorenzo@kernel.org>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"Sean Wang" <Sean.Wang@mediatek.com>,
	"kvalo@kernel.org" <kvalo@kernel.org>,
	"edumazet@google.com" <edumazet@google.com>,
	"Sujuan Chen (陈素娟)" <Sujuan.Chen@mediatek.com>,
	"Chui-hao Chiu (邱垂浩)" <Chui-hao.Chiu@mediatek.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"linux-next@vger.kernel.org" <linux-next@vger.kernel.org>,
	"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
	"Bo Jiao (焦波)" <Bo.Jiao@mediatek.com>
Subject: Re: Coverity: mt7996_hw_queue_read(): Integer handling issues
Date: Tue, 6 Dec 2022 15:37:05 -0800	[thread overview]
Message-ID: <202212061535.5D3DA489FB@keescook> (raw)
In-Reply-To: <786eff1a1751a5bc0dc68d6567be585b635bddb1.camel@mediatek.com>

On Sat, Dec 03, 2022 at 04:40:09AM +0000, Ryder Lee wrote:
> On Fri, 2022-12-02 at 14:11 -0800, coverity-bot wrote:
> > Hello!
> > 
> > This is an experimental semi-automated report about issues detected
> > by
> > Coverity from a scan of next-20221202 as part of the linux-next scan
> > project:
> > 
> https://urldefense.com/v3/__https://scan.coverity.com/projects/linux-next-weekly-scan__;!!CTRNKA9wMg0ARbw!jBOoj6LMqqA8E0AyjKQTa-0rVzcFiZ3BbpciEIn7so974kcMBeG4zZm-QU4AudLXY7-jNUSt0unzAt2zirSF$ 
> >  
> > 
> > You're getting this email because you were associated with the
> > identified
> > lines of code (noted below) that were touched by commits:
> > 
> >   Thu Dec 1 17:29:14 2022 +0100
> >     98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi
> > 7 (802.11be) devices")
> > 
> > Coverity reported the following:
> > 
> > *** CID 1527813:  Integer handling issues  (SIGN_EXTENSION)
> > drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c:460 in
> > mt7996_hw_queue_read()
> > 454     	for (i = 0; i < size; i++) {
> > 455     		u32 ctrl, head, tail, queued;
> > 456
> > 457     		if (val & BIT(map[i].index))
> > 458     			continue;
> > 459
> > vvv     CID 1527813:  Integer handling issues  (SIGN_EXTENSION)
> > vvv     Suspicious implicit sign extension: "map[i].qid" with type
> > "u8" (8 bits, unsigned) is promoted in "map[i].qid << 24" to type
> > "int" (32 bits, signed), then sign-extended to type "unsigned long"
> > (64 bits, unsigned).  If "map[i].qid << 24" is greater than
> > 0x7FFFFFFF, the upper bits of the result will all be 1.
> > 460     		ctrl = BIT(31) | (map[i].pid << 10) |
> > (map[i].qid << 24);
> 
> u32 ctrl = BIT(31) | (map[i].pid << 10) | (map[i].qid << 24);
> 
> Hmm ...where's type "int" (32 bits, signed) from?

	map[i].qid is promoted to int before the "<< 24".

-- 
Kees Cook

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-12-06 23:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02 22:11 Coverity: mt7996_hw_queue_read(): Integer handling issues coverity-bot
2022-12-02 22:11 ` coverity-bot
2022-12-03  4:40 ` Ryder Lee
2022-12-03  4:40   ` Ryder Lee
2022-12-06 23:37   ` Kees Cook [this message]
2022-12-06 23:37     ` Kees Cook

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=202212061535.5D3DA489FB@keescook \
    --to=keescook@chromium.org \
    --cc=Bo.Jiao@mediatek.com \
    --cc=Chui-hao.Chiu@mediatek.com \
    --cc=Evelyn.Tsai@mediatek.com \
    --cc=Howard-YH.Hsu@mediatek.com \
    --cc=MeiChia.Chiu@mediatek.com \
    --cc=Money.Wang@mediatek.com \
    --cc=Ryder.Lee@mediatek.com \
    --cc=Sean.Wang@mediatek.com \
    --cc=Shayne.Chen@mediatek.com \
    --cc=StanleyYP.Wang@mediatek.com \
    --cc=Sujuan.Chen@mediatek.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gustavo@embeddedor.com \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-next@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nbd@nbd.name \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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 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.