Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2939821rwb; Fri, 2 Dec 2022 18:20:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf61zJ2UY8PxFJi5bcEE+pPzy0XPCrGzDi3g//i2QZ2J87ERGRv9llap8D4onGj0xqdATVVp X-Received: by 2002:a17:906:8d07:b0:7c0:c10e:82d3 with SMTP id rv7-20020a1709068d0700b007c0c10e82d3mr4941249ejc.391.1670034052646; Fri, 02 Dec 2022 18:20:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670034052; cv=none; d=google.com; s=arc-20160816; b=QKhOFoiylfXCwguZEjEsLrI5Ps1jJtgahrPblxpyEAQkMXjevT+cylZOGoKnjPja/S NIpPXNrHYBflDEAexewimdziXvkUClemyB5OJh4j0OFnSt+2/4GLURuhK/ft2C9HMiDe 2ahbCC+KKfkSUgC2CljUyZ0P3E1WKkws/tY9E09riQVZmtqgAyiftZj3ILkMT5xtaKtD w1i1yO8bnDKK8Si4YFO8b9fhGFBb7SfIb6HDZnCZZN+2o48TMaPKlVw/zg+VzwYY1RuK ZIXPp1Cd8oj6sPbIEj4aJVsSJNQUcWXaHZRqmVtSshg9sy51nPlgOsY+dWDBeVfj2iiJ EWsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=KslJTB66xKixbMkJwqpVpZSA0E9W1pT9X9b2hTanY44=; b=e3D4hvGTI351DNGd3phl3GqLGCTBAYEpW/vXpQvUv2a1ZZYdBQEHG3jWBnN0R0IYcW Pp7ietegd4oorplg/IxowyVCHlaMTAqD/kNElCZDV7OQmXDpAdcXD+vno38eR8ROXmbM 9zhvkq2G1VxfXREAFK+h7wI34JetyuktLjz4urehH3NXwdtSx37fg3fSlfBeX0txJgpk buDVVGmsVlz0weVUbs5eonA1AZ86nyDomd4E34asFf1T96S8s5e+s3rwCs1fkUDZlgTp qHeXYWS27h3xPxSkvfhmIWE8vmlAMQTP1Q0EpbSr6OEFZzAFmqCy+Gn4VRP1t8lQ7r0Z c6Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FdRPAwVZ; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xg12-20020a170907320c00b007ae5b41855fsi5340028ejb.895.2022.12.02.18.20.33; Fri, 02 Dec 2022 18:20:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FdRPAwVZ; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235098AbiLCCRe (ORCPT + 66 others); Fri, 2 Dec 2022 21:17:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234947AbiLCCRc (ORCPT ); Fri, 2 Dec 2022 21:17:32 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41FB6DBF55 for ; Fri, 2 Dec 2022 18:17:31 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id s196so5828290pgs.3 for ; Fri, 02 Dec 2022 18:17:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=KslJTB66xKixbMkJwqpVpZSA0E9W1pT9X9b2hTanY44=; b=FdRPAwVZYUKWI0GixKt1/Mt+MzbcNPYjYP0eTaKVlj9agMe+JiJxyY5avV9WtorCm+ EK+OYvzUfadggHErH3DkUit8KsSW1LwHMxmJnXE6B74hzYeyVOXZyI2rEJGSVj+Q7E1e 1/TvPb0HpDfja1G3IDLH+2UgTDmiIMikYkJLc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=KslJTB66xKixbMkJwqpVpZSA0E9W1pT9X9b2hTanY44=; b=lij/6CjI6KuNwsC6Jxl0aNkuXFcLei3qd5ktP7LhCm081O3JxPpVU6SOTFB64GHrYF pgxpKjs25cfrVITigX4zpjcfGoLiZyxMSIIoH6EfeXlklHAJ+yFrqqQTVLHlrpco6E4e n104uF0W79b1tqUtUCq+L3h5GjysDRqW9g9fIsYWjFK2myUGs7e/TFJYi+W6LR14p9vg /l9wxzOVJ6hrmOEyIHUji/IrSOfLLlhi7h7//O58+/FT3H3EpJx8GAK51M4Iteh477QZ +GSKa8Awr7BkQ9qwm7iB7FyHJey10NIwa2q4kmTV8zfBjJ6JEuNZLCqj42rSfKpTw/E4 H/xw== X-Gm-Message-State: ANoB5plwP/QGTcG51GpsPYEUT+sfnNi3hxJgeyjrGymNdvrs4QEeQUYZ pqaOGopEnfwBoweGnQTCFRvLJQ== X-Received: by 2002:a05:6a00:1409:b0:56b:e1d8:e7a1 with SMTP id l9-20020a056a00140900b0056be1d8e7a1mr54566551pfu.28.1670033850672; Fri, 02 Dec 2022 18:17:30 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y69-20020a62ce48000000b00571bdf45888sm2157422pfg.154.2022.12.02.18.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 18:17:29 -0800 (PST) Date: Fri, 2 Dec 2022 18:17:28 -0800 From: Kees Cook To: Ryder Lee Cc: MeiChia Chiu =?utf-8?B?KOmCsee+juWYiSk=?= , "linux-kernel@vger.kernel.org" , "gustavo@embeddedor.com" , "linux-mediatek@lists.infradead.org" , "linux-hardening@vger.kernel.org" , Shayne Chen =?utf-8?B?KOmZs+i7kuS4nik=?= , "nbd@nbd.name" , "lorenzo@kernel.org" , "kuba@kernel.org" , Sean Wang , "kvalo@kernel.org" , "edumazet@google.com" , Sujuan Chen =?utf-8?B?KOmZiOe0oOWonyk=?= , "pabeni@redhat.com" , "linux-arm-kernel@lists.infradead.org" , "netdev@vger.kernel.org" , "linux-next@vger.kernel.org" , "matthias.bgg@gmail.com" , "davem@davemloft.net" , Bo Jiao =?utf-8?B?KOeEpuazoik=?= , "linux-wireless@vger.kernel.org" Subject: Re: Coverity: mt7915_mcu_get_chan_mib_info(): Memory - illegal accesses Message-ID: <202212021817.E35115E1@keescook> References: <202212021424.34C0F695E4@keescook> <1a16599dd5e4eed86bae112a232a3599af43a5f2.camel@mediatek.com> <202212021504.A1942911@keescook> <6285b967a37d7f641b13ba73c10033450ee8ea7f.camel@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6285b967a37d7f641b13ba73c10033450ee8ea7f.camel@mediatek.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Fri, Dec 02, 2022 at 11:42:36PM +0000, Ryder Lee wrote: > On Fri, 2022-12-02 at 15:04 -0800, Kees Cook wrote: > > > > > On Fri, Dec 02, 2022 at 10:56:19PM +0000, Ryder Lee wrote: > > > On Fri, 2022-12-02 at 14:24 -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!j7j_C0KpO4VD2yMOodvpeIexTGq4fhy2yq6nokNua9u4LToiUOLk4ou8JFFNrXkrh80d5BK2k44faRQstHE9$ > > > > > > > > > > > > > > > You're getting this email because you were associated with the > > > > identified > > > > lines of code (noted below) that were touched by commits: > > > > > > > > Thu Feb 3 13:57:56 2022 +0100 > > > > 417a4534d223 ("mt76: mt7915: update mt7915_chan_mib_offs for > > > > mt7916") > > > > > > > > Coverity reported the following: > > > > > > > > *** CID 1527801: Memory - illegal accesses (OVERRUN) > > > > drivers/net/wireless/mediatek/mt76/mt7915/mcu.c:3005 in > > > > mt7915_mcu_get_chan_mib_info() > > > > 2999 start = 5; > > > > 3000 ofs = 0; > > > > 3001 } > > > > 3002 > > > > 3003 for (i = 0; i < 5; i++) { > > > > 3004 req[i].band = cpu_to_le32(phy->mt76->band_idx); > > > > vvv CID 1527801: Memory - illegal accesses (OVERRUN) > > > > vvv Overrunning array "offs" of 9 4-byte elements at element > > > > index 9 (byte offset 39) using index "i + start" (which evaluates > > > > to > > > > 9). > > > > 3005 req[i].offs = cpu_to_le32(offs[i + start]); > > > > 3006 > > > > 3007 if (!is_mt7915(&dev->mt76) && i == 3) > > > > 3008 break; > > > > 3009 } > > > > 3010 > > > > > > > > If this is a false positive, please let us know so we can mark it > > > > as > > > > such, or teach the Coverity rules to be smarter. If not, please > > > > make > > > > sure fixes get into linux-next. :) For patches fixing this, > > > > please > > > > include these lines (but double-check the "Fixes" first): > > > > > > > > > > I think this is a false postive as the subsequent check 'if > > > (!is_mt7915(&dev->mt76) && i == 3)' should break array "offs" of 8. > > > > Ah, okay. What if is_mt7915(&dev->mt76) is always true? > > > > -Kees > > int start = 0; > > if (!is_mt7915(&dev->mt76)) { > start = 5; > ofs = 0; > } > > for (i = 0; i < 5; i++) { > req[i].band = cpu_to_le32(phy->band_idx); > req[i].offs = cpu_to_le32(offs[i + start]); > > if (!is_mt7915(&dev->mt76) && i == 3) // > break; > } > > For 'is_mt7915' case, start:0 and i: 0 1 2 3 4, whereas !is_mt7915' > case, start:5 and i: 0 1 2 3 (then break). > > I know it's a bit tricky. This is used to differentiate chipset > revision. Ah-ha! Gotcha now. Thanks for the details and sorry for the noise! :) -Kees -- Kees Cook