Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2602336pxb; Fri, 25 Mar 2022 23:03:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxovblkN04xD1d9/RE6sXLVYuuUTPb7ZL8v+PHRZPgXuAhF5mFfKl3185ju9Ey7b4WleTw7 X-Received: by 2002:a17:907:7d93:b0:6da:8f57:68fa with SMTP id oz19-20020a1709077d9300b006da8f5768famr16017963ejc.42.1648274609810; Fri, 25 Mar 2022 23:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648274609; cv=none; d=google.com; s=arc-20160816; b=wlAYyGftc3VXNl3t23X4GFhjTMuoiRLQyxVQaaJwjplNCLcrIEoEtYiOBkHMUSWL1U uOuQqMaMuffOE4+28azKuZbbvw5VxyCuYhukTEsQDSNrV/aoIFdq0wuAqS8bsQ5JWpti owSFbSx5JA4KQfUlc1KXl+25CiEf5qWp8d9rcsyydq9SksZekYZ/OLAnLrQGJm851GLs mkkCTPuzDbDgFeBfeoy2VFaTLO49Apa5VUCnoGXKpJRGgHv+QaNzZBpAYi+yNyQi+2Gn ldU5nA/WsnF4jUdEZUq2NoUHCyhYIuTuuqcxaPLCeXpgRK9r3r4gjxfi85Oy7BD8DsRD EDBg== 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=VVmNfLvytWC951S/CtUzoyGXxk5OGkxlr9n9Bf7nR3w=; b=vhXOAfRFzmEjMTSW3YRZARxtXfWjuczmTHFoozONQNn7X4lnC+/SMtB5RPFl0w+fhu hrjdMXM60M2WCD0MxABGVlV7dZLc5XzJmUuEAlhQFgqHAxgUh2W37Hc+SQUPqtznwRIB PUuPJQtaZ/HQpNvFsgEWNu0rBrEbMVWo6gL+IMtlH8KmsxAGvB/ROltzKv5Zwk/z/+wG COZ6TOYIW0Xg4kpZxtYfnCF/6pL2wUGe2tC3Yih/McBbEuS6IodoZ1V70Kr2Sa3m2jry k9eIKBkVS0A5Ojov1Al2mwXo2DoM8dz7iyZ/KDq+el0alOGGZMXODkCTyaZavJAxp46f sHJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=N6SqGZ1X; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jv11-20020a170907768b00b006df76385f10si4806651ejc.944.2022.03.25.23.02.50; Fri, 25 Mar 2022 23:03:28 -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=@lunn.ch header.s=20171124 header.b=N6SqGZ1X; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230180AbiCZCTK (ORCPT + 99 others); Fri, 25 Mar 2022 22:19:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbiCZCTJ (ORCPT ); Fri, 25 Mar 2022 22:19:09 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [185.16.172.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73ED32645; Fri, 25 Mar 2022 19:17:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=VVmNfLvytWC951S/CtUzoyGXxk5OGkxlr9n9Bf7nR3w=; b=N6SqGZ1XcSlQGe38Kc13cyzli4 B7INNI1gSE4ASEyyowTzT75QEWAsysDH5KSH3culOmIRXntvcNvapOOsPw/yhbk4iQCEZdDu0CjZp cOJF3edhTOOH4dFS1EVv+jhbMadJkTPfg6rFrt1Qk8HtIz/kmLMD2fF+NxWWAnBlY8/g=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1nXvzS-00Cilr-BM; Sat, 26 Mar 2022 03:17:18 +0100 Date: Sat, 26 Mar 2022 03:17:18 +0100 From: Andrew Lunn To: Michael Walle Cc: Horatiu Vultur , "David S . Miller" , Jakub Kicinski , Paolo Abeni , UNGLinuxDriver@microchip.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net] net: lan966x: fix kernel oops on ioctl when I/F is down Message-ID: References: <20220326000251.2687897-1-michael@walle.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220326000251.2687897-1-michael@walle.cc> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,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 On Sat, Mar 26, 2022 at 01:02:51AM +0100, Michael Walle wrote: > A SIOCGMIIPHY ioctl will cause a kernel oops when the interface is down. > Fix it by checking the state and if it's no running, return an error. s/no/not/ I don't think it is just SIOCGMIIPHY. phy_has_hwtstamp(dev->phydev) is probably also an issue. The phy is connected in open, and disconnected in stop. So dev->phydev is not valid outside of that time. But i'm also not sure it is guaranteed to be valid while the interface is up. The driver uses phylink, so there could be an SFP attached to a port, in which case, dev->phydev will not be set. So rather than testing of running, it would be better to test if the phydev is NULL or not. Andrew > > Fixes: 735fec995b21 ("net: lan966x: Implement SIOCSHWTSTAMP and SIOCGHWTSTAMP") > Signed-off-by: Michael Walle > --- > drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c > index ec42e526f6fb..0adf49d19142 100644 > --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c > +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c > @@ -399,6 +399,9 @@ static int lan966x_port_ioctl(struct net_device *dev, struct ifreq *ifr, > { > struct lan966x_port *port = netdev_priv(dev); > > + if (!netif_running(dev)) > + return -EINVAL; > + > if (!phy_has_hwtstamp(dev->phydev) && port->lan966x->ptp) { > switch (cmd) { > case SIOCSHWTSTAMP: > -- > 2.30.2 >