Paul Mackey of Morgan Stanley recently reported problems with window
scaling in FTP upload sessions where the FTP server was configured with a
128K receive buffer (window scale 2). As the session progressed, the
client gradually got further ahead of the server, until the acks fell out
of the hardcoded 66000 (ipfilter 3.4.33) byte maximum ack slew.
I helped him analyze our packet capture, looked at the code, and as a
band-aid we recompiled and tested with a larger max slew which fixed the
problem.
There 4.0beta1 code handles window scaling more gracefully by also scaling
the maximum ack slew:
#define MAXACKWINDOW 66000
(-ackskew <= (MAXACKWINDOW << fdata->td_winscale)) &&
( ackskew <= (MAXACKWINDOW << fdata->td_winscale))) {
/* if ackskew < 0 then this should be due to fragmented
* packets. There is no way to know the length of the
* total packet in advance.
* We do know the total length from the fragment cache though.
* Note however that there might be more sessions with
* exactly the same source and destination parameters in the
* state cache (and source and destination is the only stuff
* that is saved in the fragment cache). Note further that
* some TCP connections in the state cache are hashed with
* sport and dport as well which makes it not worthwhile to
* look for them.
* Thus, when ackskew is negative but still seems to belong
* to this session, we bump up the destinations end value.
*/
if (ackskew < 0)
tdata->td_end = ack;
I am bit puzzled both by this better code and the original. While
a positive ack slew can reasonably be almost a full window behind the
sender, it seems to me that a negative slew is at most one MSS ahead of
the sender, because total seize of a fragmented TCP frame is at most equal
to the MSS. This would suggest that the bound on the negative slew can be
much smaller and independent of the window scale (after all IP
fragmentation is independent of TCP window scaling).
Secondly, the code allows negative ack slew to permanently advance
tdata->td_end, and repeated slewed acks can move td->td_end arbitrarily
far away from the actual sender state without any corresponding
transmission from the sender.
It seems to me, that the (at most 1*MSS) uncertainty in the sender's
*next* sequence number should be calculated separately from tdata->td_end,
only observed packets from the sender should advance td_end, with the
uncertainty taken into account when the value is used.
While I cannot off hand think of any security consequences of allowing the
recipient to arbitrarily advance the sender sequence number, the mere
possibility makes me uneasy for reasons I can not at this time rationally
justify.
Please forgive my ignorance, I could easily be the victim of my own
limited exposure to the problem space and IPFilter code. If I am missing
something important, please clue me in. If with luck there is a
kernel of truth in the above rant, perhaps someone can polish it into a
better formed analysis that might lead to improvements in the code.
Thanks in advance.
--
Victor Duchovni
IT Security,
Morgan Stanley