Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2190502iof; Tue, 7 Jun 2022 22:40:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyebDYMdQD5FkOgHRtzZDZ9t0PCdjNM2oYKSQJweyV5fnLFyG+QeNXm+mScXexIU/RkbeJU X-Received: by 2002:a63:d013:0:b0:3fc:e50f:8e2a with SMTP id z19-20020a63d013000000b003fce50f8e2amr26668536pgf.283.1654666857910; Tue, 07 Jun 2022 22:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666857; cv=none; d=google.com; s=arc-20160816; b=Jry+z9BWB8af9ykMjsKop5uXW2q2AopMwCAVOggJudhJeI06U6Mso102JWfr5csOBY z0HvyfCPtTgZsxyQcKzHWMT4pNKCZApcZ7i0isybkGKlMAF/OM80GDNpyZUBN7T4Uat2 LGb08WY3Sn3cbsc0vJlm+TiFsCcnmuBosJ2AvJzJi0BlVvYlz+D7Xp+/IgrenIFENcDD pnvH16nkEkVoeCusOsRn8AkKg4gdT+iK7tYgiD+h7JihSqSdNq7vxLiTldJMkuR3/s/D tZ7CrAj6daYgGJpsR3RyK6J15t0EMiVs2lhx/IMXKE6zLfYPy8Tw+SqFFOANZxI2jml9 b0eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZQYmjAdT/3BaAwDNMQ0aA285vD2TssYZUMxKHDwcAfk=; b=l1omqwNE+wRhVsuQ0s7vjqPyG6WrkMv5Y4jLkKGURUci8xg2C2X7UpMIiFO1km7pPP 9ngW3+l6P41eI53uzRdveKyvB4aTmKQJL/nSsFD3/qE5eJanbSMwq2ulNB9yCkMWO790 nbmSAoYaYFhWq39mOL5VA2hNIbLmU357DxgeNJCoayZ7FOS3hQni3/qFWbBMvxV6cY5T Dk+DtcCWy8PY33CFQ6ntGP6jyLG7Q6Z3UXTyDLiq+vvWThKBQHKmEps4NmHF1DkL2HbO GAAiG/61VMZqu4BlLtZnlYBzTKcerlJJCWvMlRvz8EhKo4iErCSYRAwgRcTRS+PRpeO4 svYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I+FAD5AN; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t18-20020a170902e85200b00163a83d160asi28565298plg.168.2022.06.07.22.40.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:40:57 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I+FAD5AN; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 81E5338DD2E; Tue, 7 Jun 2022 22:06:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383180AbiFGWkP (ORCPT + 99 others); Tue, 7 Jun 2022 18:40:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379528AbiFGVZq (ORCPT ); Tue, 7 Jun 2022 17:25:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95F5522871B; Tue, 7 Jun 2022 12:01:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 019CAB8220B; Tue, 7 Jun 2022 19:01:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EB63C385A5; Tue, 7 Jun 2022 19:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628509; bh=LQq/7blpbZyhfx4zRTEyWiRAUMsgZCLnSCZeVlsS+RE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I+FAD5ANiGV5TI/769ITUsqdpOzN998TTd+wuBzq4jhuNPnEldtpmD21sXL3iXc4k 3ZP1pl4ufwAR4FBEhRaHvq3TsgWMY8nsUZHpYLP75gV6G49AM7u+F3OpxFxEYUD4gB e1/ifH3KQXmeQDQMWO491Bo6t658pF8W8nnCx/pY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Wei Yongjun , Adam Ward , Mark Brown , Sasha Levin Subject: [PATCH 5.18 328/879] regulator: da9121: Fix uninit-value in da9121_assign_chip_model() Date: Tue, 7 Jun 2022 18:57:26 +0200 Message-Id: <20220607165012.374554430@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org From: Wei Yongjun [ Upstream commit bab76514aca36bc513224525d5598da676938218 ] KASAN report slab-out-of-bounds in __regmap_init as follows: BUG: KASAN: slab-out-of-bounds in __regmap_init drivers/base/regmap/regmap.c:841 Read of size 1 at addr ffff88803678cdf1 by task xrun/9137 CPU: 0 PID: 9137 Comm: xrun Tainted: G W 5.18.0-rc2 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 Call Trace: dump_stack_lvl+0xe8/0x15a lib/dump_stack.c:88 print_report.cold+0xcd/0x69b mm/kasan/report.c:313 kasan_report+0x8e/0xc0 mm/kasan/report.c:491 __regmap_init+0x4540/0x4ba0 drivers/base/regmap/regmap.c:841 __devm_regmap_init+0x7a/0x100 drivers/base/regmap/regmap.c:1266 __devm_regmap_init_i2c+0x65/0x80 drivers/base/regmap/regmap-i2c.c:394 da9121_i2c_probe+0x386/0x6d1 drivers/regulator/da9121-regulator.c:1039 i2c_device_probe+0x959/0xac0 drivers/i2c/i2c-core-base.c:563 This happend when da9121 device is probe by da9121_i2c_id, but with invalid dts. Thus, chip->subvariant_id is set to -EINVAL, and later da9121_assign_chip_model() will access 'regmap' without init it. Fix it by return -EINVAL from da9121_assign_chip_model() if 'chip->subvariant_id' is invalid. Fixes: f3fbd5566f6a ("regulator: da9121: Add device variants") Reported-by: Hulk Robot Signed-off-by: Wei Yongjun Reviewed-by: Adam Ward Link: https://lore.kernel.org/r/20220421090335.1876149-1-weiyongjun1@huawei.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/regulator/da9121-regulator.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/regulator/da9121-regulator.c b/drivers/regulator/da9121-regulator.c index eb9df485bd8a..76e0e23bf598 100644 --- a/drivers/regulator/da9121-regulator.c +++ b/drivers/regulator/da9121-regulator.c @@ -1030,6 +1030,8 @@ static int da9121_assign_chip_model(struct i2c_client *i2c, chip->variant_id = DA9121_TYPE_DA9142; regmap = &da9121_2ch_regmap_config; break; + default: + return -EINVAL; } /* Set these up for of_regulator_match call which may want .of_map_modes */ -- 2.35.1