netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: dsa: avoid potential use-after-free error
@ 2020-11-18 15:43 Christian Eggers
  2020-11-18 23:33 ` Vladimir Oltean
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Eggers @ 2020-11-18 15:43 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, Vladimir Oltean
  Cc: Vivien Didelot, David S . Miller, Jakub Kicinski, netdev,
	linux-kernel, Christian Eggers

If dsa_switch_ops::port_txtstamp() returns false, clone will be freed
immediately. Storing the pointer in DSA_SKB_CB(skb)->clone anyway,
supports annoying use-after-free bugs.

Signed-off-by: Christian Eggers <ceggers@arri.de>
Fixes 146d442c2357 ("net: dsa: Keep a pointer to the skb clone for TX timestamping")
---
 net/dsa/slave.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index ff2266d2b998..7efc753e4d9d 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -522,10 +522,10 @@ static void dsa_skb_tx_timestamp(struct dsa_slave_priv *p,
 	if (!clone)
 		return;
 
-	DSA_SKB_CB(skb)->clone = clone;
-
-	if (ds->ops->port_txtstamp(ds, p->dp->index, clone, type))
+	if (ds->ops->port_txtstamp(ds, p->dp->index, clone, type)) {
+		DSA_SKB_CB(skb)->clone = clone;
 		return;
+	}
 
 	kfree_skb(clone);
 }
-- 
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] net: dsa: avoid potential use-after-free error
  2020-11-18 15:43 [PATCH net-next] net: dsa: avoid potential use-after-free error Christian Eggers
@ 2020-11-18 23:33 ` Vladimir Oltean
  2020-11-19  5:27   ` Christian Eggers
  0 siblings, 1 reply; 3+ messages in thread
From: Vladimir Oltean @ 2020-11-18 23:33 UTC (permalink / raw)
  To: Christian Eggers
  Cc: Andrew Lunn, Florian Fainelli, Vivien Didelot, David S . Miller,
	Jakub Kicinski, netdev, linux-kernel

On Wed, Nov 18, 2020 at 04:43:35PM +0100, Christian Eggers wrote:
> If dsa_switch_ops::port_txtstamp() returns false, clone will be freed
> immediately. Storing the pointer in DSA_SKB_CB(skb)->clone anyway,
> supports annoying use-after-free bugs.

Like what?

> Signed-off-by: Christian Eggers <ceggers@arri.de>
> Fixes 146d442c2357 ("net: dsa: Keep a pointer to the skb clone for TX timestamping")

Not the right format for a Fixes: tag, please try to set up your
.gitconfig to automate the creation of this tag.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] net: dsa: avoid potential use-after-free error
  2020-11-18 23:33 ` Vladimir Oltean
@ 2020-11-19  5:27   ` Christian Eggers
  0 siblings, 0 replies; 3+ messages in thread
From: Christian Eggers @ 2020-11-19  5:27 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Andrew Lunn, Florian Fainelli, Vivien Didelot, David S . Miller,
	Jakub Kicinski, netdev, linux-kernel

On Thursday, 19 November 2020, 00:33:57 CET, Vladimir Oltean wrote:
> On Wed, Nov 18, 2020 at 04:43:35PM +0100, Christian Eggers wrote:
> > If dsa_switch_ops::port_txtstamp() returns false, clone will be freed
> > immediately. Storing the pointer in DSA_SKB_CB(skb)->clone anyway,
> > supports annoying use-after-free bugs.
> 
> Like what?
In my own code. I test for DSA_SKB_CB(skb)->clone in order to determine 
whether a skb has been selected for TX time stamping by 
ksz9477_ptp_port_txtstamp().

> 
> > Signed-off-by: Christian Eggers <ceggers@arri.de>
> > Fixes 146d442c2357 ("net: dsa: Keep a pointer to the skb clone for TX
> > timestamping")
> Not the right format for a Fixes: tag, please try to set up your
> .gitconfig to automate the creation of this tag.
I think you (or somebody else) already noted this. Sorry for postponing.

regards
Christian




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-19  5:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18 15:43 [PATCH net-next] net: dsa: avoid potential use-after-free error Christian Eggers
2020-11-18 23:33 ` Vladimir Oltean
2020-11-19  5:27   ` Christian Eggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).