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 X-Spam-Level: X-Spam-Status: No, score=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C96AEC47254 for ; Tue, 5 May 2020 13:19:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 94BA9206A5 for ; Tue, 5 May 2020 13:19:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="VS9bEppu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729058AbgEENTi (ORCPT ); Tue, 5 May 2020 09:19:38 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:42434 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728512AbgEENTi (ORCPT ); Tue, 5 May 2020 09:19:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=cOGZMDYDg91AdmJwbZJ05nNM/oJQN2A62u8nZ70fMzc=; b=VS9bEppuNnpoJTurjp7fm2M6Ul 9ekYJP8XV/RYiCBi9GQdgC/YdzCqqni0NtzRI1TTprSpiOQyXE6riVtOAosQG4h0DQ65gXnmiBpnZ 52OjQln2RKo7K0dvmaP4EFOdy/dG2Ys/rc26xROPl8JL0Gvcr0d6IYB5UIfUkvAHNxbY=; Received: from andrew by vps0.lunn.ch with local (Exim 4.93) (envelope-from ) id 1jVxU0-000w3y-En; Tue, 05 May 2020 15:19:36 +0200 Date: Tue, 5 May 2020 15:19:36 +0200 From: Andrew Lunn To: Michal Kubecek Cc: David Miller , netdev , Florian Fainelli , Heiner Kallweit , Chris Healy , michael@walle.cc Subject: Re: [PATCH net-next v2 06/10] net: ethtool: Add infrastructure for reporting cable test results Message-ID: <20200505131936.GF208718@lunn.ch> References: <20200505001821.208534-1-andrew@lunn.ch> <20200505001821.208534-7-andrew@lunn.ch> <20200505104226.GJ8237@lion.mk-sys.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200505104226.GJ8237@lion.mk-sys.cz> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org > > +int ethnl_cable_test_alloc(struct phy_device *phydev) > > +{ > > + int err = -ENOMEM; > > + > > + phydev->skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); > > + if (!phydev->skb) > > + goto out; > > + > > + phydev->ehdr = ethnl_bcastmsg_put(phydev->skb, > > + ETHTOOL_MSG_CABLE_TEST_NTF); > > + if (!phydev->ehdr) { > > + err = -EINVAL; > > This should be -EMSGSIZE. > > > + goto out; > > + } > > + > > + err = ethnl_fill_reply_header(phydev->skb, phydev->attached_dev, > > + ETHTOOL_A_CABLE_TEST_NTF_HEADER); > > + if (err) > > + goto out; > > + > > + err = nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_TEST_NTF_STATUS, > > + ETHTOOL_A_CABLE_TEST_NTF_STATUS_COMPLETED); > > + if (err) > > + goto out; > > + > > + phydev->nest = nla_nest_start(phydev->skb, > > + ETHTOOL_A_CABLE_TEST_NTF_NEST); > > + if (!phydev->nest) > > + goto out; > > If nla_nest_start() fails, we still have 0 in err. > > > + > > + return 0; > > + > > +out: > > + nlmsg_free(phydev->skb); > > + return err; > > +} > > +EXPORT_SYMBOL_GPL(ethnl_cable_test_alloc); > > Do you think it would make sense to set phydev->skb to NULL on failure > and also in ethnl_cable_test_free() and ethnl_cable_test_finished() so > that if driver messes up, it hits null pointer dereference which is much > easier to debug than use after free? Hi Michal The use after free is not that hard to debug, i had to do it myself :-) But yes, i can poison phydev->skb. Andrew