Open kees opened 2 years ago
@kuba-moo
We don't have an API for just length checking currently. We have two APIs, AFAIK: pskb_may_pull() and skb_header_pointer(). The difference between the two is that the first one pulls the data into the linear portion of the skb while the latter may return a pointer to a scratch buffer if whatever it wants to access is in paged memory. Note that IIRC neither of them guarantees that caller is granted write access, appropriate CoW helper needs to be called before writing. Your helper suggestion seems good (modulo the fact that my eyes need to get used to the pointer-type-implies-size concept), but you'd need to answer the two aspects from above - does the helper pull or fail? Does it CoW or returns read-only pointer? Or perhaps it can only be used on non-cloned skbs?
There have been bugs of the form:
This needs to use a common accessor (like skb kind of uses), so that both
offset
andsizeof(*instance)
are checked against overflows vssize
. (Note thatoffset
may be 0 or not added at all, andinstance
may be a pointer to a non-struct type.) For example, something like this would be able to do all the overflow checking:See also issue #140