Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3326277rwa; Tue, 23 Aug 2022 02:54:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR7fJeYn2/SswuPP/Jod5BCMB6eICncXI0NcZOfuXtyaQi5EgfBhQ42cAftbPH+Fg4CcCUlL X-Received: by 2002:a17:907:6295:b0:703:92b8:e113 with SMTP id nd21-20020a170907629500b0070392b8e113mr16270264ejc.594.1661248482213; Tue, 23 Aug 2022 02:54:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248482; cv=none; d=google.com; s=arc-20160816; b=Wfkl0kuN+rXHF+QH79ql8QsATD+AJHErk+Kosq72W43EXj6J9nsZfj1xL64pE+LE2a vhJfy2p+M9i4f8y2IfA53+6Cj0RRMV2SmBPYL6Mm9rNgq0GDwqOIGych7yOQ4OAoPz4+ 3GLPir4eesNfFH+Vv1vh+Y7QreB43hFnp1BzwM8yHGjnWLo0rDr8En8X1N/O+/0RQf9g hpMQqESwyIpKjCUj27VNa4Ij0NwdcPXO95qPFb45NQ/hmqp55djq8RCXkod8jlNhPw4O HQX3RSrD7ie7kdHROux9Qduxn8S2frs0X3ZEej9IsWTmWLca7+K2zbM+RRQrFTdOywep wjJA== 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=G4YOK0VUIY8RnijXT33pinOvautbkrfOiSEZoJUCD4Y=; b=Uy4ieGwgSwgsDYtwP/9jXVVPEQh7R+LXHUc6IYD6TwWp86GYTpFbwtuh/fiB8zGFAL x98N5ckMbxZSOIcTp5VNFHu2ZbocF+JwI7SCYnnx+poMC5NhXUDFZZmXbs2aXIcWWRFF ZJZJCj9c4KnDxPHa3g9VoUmc5rJIR/0sjaNyyRn2+wtFH2xuA9CPPLxtW4I2U83NvggD JXyY+oE8j2jh7loxQOIoCkCShblU+qq1pbZQ9AkHSxVctdN7IzChVedfKgAJU6l1SsqQ BytT8tOuE9yz1h/vHdsY6Tmz0EAjYWPKgmlQH3cylxMfjIcX0xe0iLT1JmycZ3ROYrv+ lEKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tzAox7Vv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y4-20020a50e604000000b00446cd5b771dsi1498798edm.223.2022.08.23.02.54.15; Tue, 23 Aug 2022 02:54:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=tzAox7Vv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243584AbiHWI2l (ORCPT + 99 others); Tue, 23 Aug 2022 04:28:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243328AbiHWIY3 (ORCPT ); Tue, 23 Aug 2022 04:24:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 684AB1836B; Tue, 23 Aug 2022 01:13:28 -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 dfw.source.kernel.org (Postfix) with ESMTPS id C9AB361324; Tue, 23 Aug 2022 08:13:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C22B0C433C1; Tue, 23 Aug 2022 08:13:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661242382; bh=198MJV5Vfc/FGWCXHEV8mqffz6z2Dlc0B5J2AMGuxB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tzAox7Vvg2s3HR7LbJhj0OMtp/ITaM78a42faJLH+8RfabHB7twnEz9OzwenVmwWr EAbLD1TJpV9PGMEJ9RBOpLSox4HD3G9CXhEt7TYBSCDavcoiS2cIroC95jdOvqTBKx tvqZ3i8KSa0ajnl8tNFriTh2VoKf5WaRG9fyZ58Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Laura Abbott , Kees Cook , Daniel Micay , Guenter Roeck Subject: [PATCH 4.9 063/101] nios2: time: Read timer in get_cycles only if initialized Date: Tue, 23 Aug 2022 10:03:36 +0200 Message-Id: <20220823080036.986294626@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080034.579196046@linuxfoundation.org> References: <20220823080034.579196046@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Guenter Roeck commit 65d1e3ddeae117f6a224535e10a09145f0f96508 upstream. Mainline crashes as follows when running nios2 images. On node 0 totalpages: 65536 free_area_init_node: node 0, pgdat c8408fa0, node_mem_map c8726000 Normal zone: 512 pages used for memmap Normal zone: 0 pages reserved Normal zone: 65536 pages, LIFO batch:15 Unable to handle kernel NULL pointer dereference at virtual address 00000000 ea = c8003cb0, ra = c81cbf40, cause = 15 Kernel panic - not syncing: Oops Problem is seen because get_cycles() is called before the timer it depends on is initialized. Returning 0 in that situation fixes the problem. Fixes: 33d72f3822d7 ("init/main.c: extract early boot entropy from the ..") Cc: Laura Abbott Cc: Kees Cook Cc: Daniel Micay Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- arch/nios2/kernel/time.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/arch/nios2/kernel/time.c +++ b/arch/nios2/kernel/time.c @@ -107,7 +107,10 @@ static struct nios2_clocksource nios2_cs cycles_t get_cycles(void) { - return nios2_timer_read(&nios2_cs.cs); + /* Only read timer if it has been initialized */ + if (nios2_cs.timer.base) + return nios2_timer_read(&nios2_cs.cs); + return 0; } EXPORT_SYMBOL(get_cycles);