Bug 240135 - Correctness issue in IPv6 extension headers input processing routines
Summary: Correctness issue in IPv6 extension headers input processing routines
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Bjoern A. Zeeb
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-26 21:35 UTC by Prabhakar Lakhera
Modified: 2019-11-12 15:47 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Prabhakar Lakhera 2019-08-26 21:35:01 UTC
There seems to be a correctness issue in pr_inputs defined for various extension header processing routines for IPv6.
The routines call IP6_EXTHDR_* macros which may end up releasing the mbuf passed to the routine.
Even though the functions are passed pointer to the pointer to mbuf, the pointer is not updated before returning from the routine even for the cases that may not return IPPROTO_DONE.
Change would be to simply update the mbuf pointer along with updating the offset.

Please refer to implementation of route6_input/dest6_input
Comment 1 Bjoern A. Zeeb freebsd_committer 2019-11-06 13:21:58 UTC
I think I have fixed this in a local tree as part of removing most of the PULLDOWN_TEST and IP6_EXTHDR* foo.

I'll hopefully upload a clean patch for review later today and will point you at it.  It's really helpful to have another pair of eyes on these things.
Comment 2 commit-hook freebsd_committer 2019-11-12 15:47:29 UTC
A commit references this bug:

Author: bz
Date: Tue Nov 12 15:46:30 UTC 2019
New revision: 354643
URL: https://svnweb.freebsd.org/changeset/base/354643

Log:
  netinet*: update *mp to pass the proper value back

  In ip6_[direct_]input() we are looping over the extension headers
  to deal with the next header.  We pass a pointer to an mbuf pointer
  to the handling functions.  In certain cases the mbuf can be updated
  there and we need to pass the new one back.  That missing in
  dest6_input() and route6_input().  In tcp6_input() we should also
  update it before we call tcp_input().

  In addition to that mark the mbuf NULL all the times when we return
  that we are done with handling the packet and no next header should
  be checked (IPPROTO_DONE).  This will eventually allow us to assert
  proper behaviour and catch the above kind of errors more easily,
  expecting *mp to always be set.

  This change is extracted from a larger patch and not an exhaustive
  change across the entire stack yet.

  PR:			240135
  Reported by:		prabhakar.lakhera gmail.com
  MFC after:		3 weeks
  Sponsored by:		Netflix

Changes:
  head/sys/netinet/tcp_input.c
  head/sys/netinet6/dest6.c
  head/sys/netinet6/frag6.c
  head/sys/netinet6/icmp6.c
  head/sys/netinet6/ip6_input.c
  head/sys/netinet6/route6.c
  head/sys/netinet6/udp6_usrreq.c