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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 999BFC61DA4 for ; Thu, 2 Feb 2023 17:18:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B85BE6B0071; Thu, 2 Feb 2023 12:18:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0EAC6B0073; Thu, 2 Feb 2023 12:18:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 988146B0078; Thu, 2 Feb 2023 12:18:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8358D6B0071 for ; Thu, 2 Feb 2023 12:18:06 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 577F9120FE3 for ; Thu, 2 Feb 2023 17:18:06 +0000 (UTC) X-FDA: 80423009772.04.B8506E1 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf30.hostedemail.com (Postfix) with ESMTP id 613188001C for ; Thu, 2 Feb 2023 17:18:04 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=dpHYoO5y; spf=pass (imf30.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.180 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675358284; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GzPZSiuWUI10A7nGN6F8afAigmnE11O3pPivhXt2BI4=; b=RHyLaQJPRVr1hJj6e2XaFTguWSgvhv8InNFhRjzkAvVtGnEyx6LmBTz0oGr9yetNjMqxaW wJnf8jpsFLLzz1MRUWW87srpQFAaOhMU7AM9qjz03lEwxt2e34x/OT5Q4ZJcBfliR8ObG7 jLYyTP/R8Lqp0aWPJnm3pUWYj7e599Y= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=dpHYoO5y; spf=pass (imf30.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.180 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675358284; a=rsa-sha256; cv=none; b=nP1UvM1VS5XQJ3EmMp+IXMwo6sRBYQKbpxMsDjvcGhbhxDdOJuE9MnvKNRwvfnzSVrQ2hX Iv9iWG3cFIGpzxlZ03M3aAbLIYMTtlwGOIiXHgvw5lwTNBPS8Jp/7FphDr957x9MrbYdL3 4GJFYEe1fp8z1zCrFc8GrHPwI7w9V5E= Received: by mail-pl1-f180.google.com with SMTP id jh15so2517703plb.8 for ; Thu, 02 Feb 2023 09:18:04 -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:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=GzPZSiuWUI10A7nGN6F8afAigmnE11O3pPivhXt2BI4=; b=dpHYoO5y+OJzvw3hGh02/zVMmdMTJw2GNRwNYUmBR9S5mEwDYnnjfhWj3vcd0NzELc RzqS1lmRY2x7oL8uGlK9ffLCq/6dXY3SHEd0ntFF+KKrHFszfA2H+YGJCAqIAH7kW+Ca JXES2+8RBP6vRmTeDLzU15Dy9G/WIuqlw866Q= 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:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=GzPZSiuWUI10A7nGN6F8afAigmnE11O3pPivhXt2BI4=; b=FxjTDbmbvVqHlaZH4gpnnmmUEIEvxUqisL3tBkYh0pJtUoCUKpx2ebFh+Mv5yO+096 m88zqOQvuVHn3+PHGEfCo9uubQhKdAJRKFjVzix0BnVJcU4rzuAGYVFTlZ8adorxY98+ Pf/O6b4CODPhj9tkj0oPmiWdEvBWiwVICoYurBwXU/sGotaH8QPngzFsguhPLdxi3L8x GmQqaJd9GT+2GWGGVtX3Fb22VGVJxwnRi5jr1KP7bV2A9GHedX2/nfSmRyHmNKFPg6QE puvYzDXE+bswNkORrovJ1z2mYTpJLD1GM3T13fL2LvEZnBWM9GIaZBV09pw4MMjSC/6D uB2Q== X-Gm-Message-State: AO0yUKWsuMv30qK9Xm03+arlsnIM7ghDa61LRGsjmPn77tmYbtpLyB8s Iv2MczNVua0CzsPqavyUZ7X0gA== X-Google-Smtp-Source: AK7set+NnIMQt6YlrSXhpTD9hAeLNLeG9CybmFZKQfwYo9yvWLqWvFDYemIeU9FbReu1DptcIqIdIg== X-Received: by 2002:a05:6a20:9f9b:b0:b8:ca86:d1e8 with SMTP id mm27-20020a056a209f9b00b000b8ca86d1e8mr2663317pzb.14.1675358283121; Thu, 02 Feb 2023 09:18:03 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id o6-20020a637306000000b004d346876d37sm36860pgc.45.2023.02.02.09.18.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 09:18:02 -0800 (PST) Message-ID: <63dbf04a.630a0220.2608a.0149@mx.google.com> X-Google-Original-Message-ID: <202302021717.@keescook> Date: Thu, 2 Feb 2023 17:18:01 +0000 From: Kees Cook To: John Stultz Cc: Yongqin Liu , Vlastimil Babka , Greg Kroah-Hartman , Rasmus Villemoes , Thomas Gleixner , Jason Gunthorpe , Nishanth Menon , Michael Kelley , Dan Williams , Won Chung , David Gow , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Guenter Roeck , Andy Shevchenko , Paolo Abeni , Geert Uytterhoeven , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev, Sumit Semwal Subject: Re: [PATCH 5/6] driver core: Add __alloc_size hint to devm allocators References: <20221101222520.never.109-kees@kernel.org> <20221101223321.1326815-5-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 613188001C X-Stat-Signature: ut9q4rqz8og7zes9w1fz3kkrpu97c4tc X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1675358284-463227 X-HE-Meta: U2FsdGVkX19nzFzhOaZPeXAoGP6YbqEgozfI6rhnQAT/CLMmzo9tmLQ/Aeav+/W+tSAHyS5xmLX1ZGUmvgoOuHQIhGWhn1ybFpJUVeOcrryIgT0IaX4e3EmWce7XImH71y8JTUsG8EB9LnBoizgg4tlnN1aPRiZzWWcFeCvk8z7RMpS/TBsEUsDnvWHeqBOWsTYe/z+c7ruFtPco0ry7nPpjx/xHnKr6iwjGu9MqLXHSEllFNTR1VRL4rv2mdE+H7LDZN3ZhdjqecZgZVikhCH84kJ4/deKzsM3GxcqYDXhdHfBVeVWuHPZDGL3i6cTyhrR6YbbcPRM5l82AfiucoqiamJhzSuSgJMqUnOuxNmJvlEW9hwOiXnjQYxOXSV11bzDpVoaNCH3yU1hjPv9gliyo8BKWZKQGqWChuPx/ye3isQnL4yWmWJlv6N+lviBF486l5mz31EUrgbKUXCZVjdDjxPAxBheMp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Kym13hYp89oo X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Feb 01, 2023 at 12:11:41AM -0800, John Stultz wrote: > On Tue, Jan 31, 2023 at 11:36 PM Yongqin Liu wrote: > > > > Hi, Kees > > > > This change causes "Kernel panic - not syncing: BRK handler: Fatal exception" > > for the android-mainline based hikey960 build, with this commit reverted, > > there is no problem for the build to boot to the homescreen. > > Not sure if you have any idea about it and give some suggestions. > > > > Here is part of the kernel panic log: > > > > [ 9.479878][ T122] ueventd: Loading module > > /vendor/lib/modules/spi-pl022.ko with args '' > > [ 9.480276][ T115] apexd-bootstrap: Pre-allocated loop device 29 > > [ 9.480517][ T123] ueventd: LoadWithAliases was unable to load > > of:Nhi3660_i2sT(null)Chisilicon,hi3660-i2s-1.0 > > [ 9.480632][ T121] Unexpected kernel BRK exception at EL1 > > [ 9.480637][ T121] Internal error: BRK handler: > > 00000000f2000001 [#1] PREEMPT SMP > > [ 9.480644][ T121] Modules linked in: cpufreq_dt(E+) > > hisi_thermal(E+) phy_hi3660_usb3(E) btqca(E) hi6421_pmic_core(E) > > btbcm(E) spi_pl022(E) hi3660_mailbox(E) i2c_designware_platform(E) > > mali_kbase(OE) dw_mmc_k3(E) bluetooth(E) dw_mmc_pltfm(E) dw_mmc(E) > > kirin_drm(E) rfkill(E) kirin_dsi(E) i2c_designware_core(E) k3dma(E) > > drm_dma_helper(E) cma_heap(E) system_heap(E) > > [ 9.480688][ T121] CPU: 4 PID: 121 Comm: ueventd Tainted: G > > OE 6.2.0-rc6-mainline-14196-g1d9f94ec75b9 #1 > > [ 9.480694][ T121] Hardware name: HiKey960 (DT) > > [ 9.480697][ T121] pstate: 20400005 (nzCv daif +PAN -UAO -TCO > > -DIT -SSBS BTYPE=--) > > [ 9.480703][ T121] pc : hi3660_thermal_probe+0x6c/0x74 [hisi_thermal] > > [ 9.480722][ T121] lr : hi3660_thermal_probe+0x38/0x74 [hisi_thermal] > > [ 9.480733][ T121] sp : ffffffc00aa13700 > > [ 9.480735][ T121] x29: ffffffc00aa13700 x28: 0000007ff8ae8531 > > x27: 00000000000008c0 > > [ 9.480743][ T121] x26: ffffffc00aa2a300 x25: ffffffc00aa2ab40 > > x24: 000000000000001d > > [ 9.480749][ T121] x23: ffffffc00a29d000 x22: 0000000000000000 > > x21: ffffff8001fa4a80 > > [ 9.480755][ T121] x20: 0000000000000001 x19: ffffff8001fa4a80 > > x18: ffffffc00a8810b0 > > [ 9.480761][ T121] x17: 000000007ab542f2 x16: 000000007ab542f2 > > x15: ffffffc00aa01000 > > [ 9.480767][ T121] x14: ffffffc00966f250 x13: ffffffc0b58f9000 > > x12: ffffffc00a055f10 > > [ 9.480771][ T123] ueventd: LoadWithAliases was unable to load > > cpu:type:aarch64:feature:,0000,0001,0002,0003,0004,0005,0006,0007,000B > > [ 9.480773][ T121] > > [ 9.480774][ T121] x11: 0000000000000000 x10: 0000000000000001 > > x9 : 0000000100000000 > > [ 9.480780][ T123] ueventd: > > [ 9.480780][ T121] x8 : ffffffc0044154cb x7 : 0000000000000000 > > x6 : 000000000000003f > > [ 9.480786][ T121] x5 : 0000000000000020 x4 : ffffffc0098db323 > > x3 : ffffff801aeb62c0 > > [ 9.480792][ T121] x2 : ffffff801aeb62c0 x1 : 0000000000000000 > > x0 : ffffff8001fa4c80 > > [ 9.480798][ T121] Call trace: > > [ 9.480801][ T121] hi3660_thermal_probe+0x6c/0x74 [hisi_thermal] > > [ 9.480813][ T121] hisi_thermal_probe+0xbc/0x284 [hisi_thermal] > > > Taking a look here, it looks pretty obvious: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/thermal/hisi_thermal.c#n414 > > data->nr_sensors = 1; > data->sensor = devm_kzalloc(dev, sizeof(*data->sensor) * > data->nr_sensors, GFP_KERNEL); > > Here as nr_sensors=1, we allocate only one structure for the array. > But then below that, we modify two entries, writing past the valid > array, and corrupting data when writing the second sensor values. > > data->sensor[0].id = HI3660_BIG_SENSOR; > data->sensor[0].irq_name = "tsensor_a73"; > data->sensor[0].data = data; > > data->sensor[1].id = HI3660_LITTLE_SENSOR; > data->sensor[1].irq_name = "tsensor_a53"; > data->sensor[1].data = data; > > I suspect nr_sensors needs to be set to 2. > > Nice work, Kees! Yay for compilers! :) Was a patch sent to fix this driver? -- Kees Cook