Skip to content

Commit 20e2a86

Browse files
pcmooredavem330
authored andcommitted
cipso: handle CIPSO options correctly when NetLabel is disabled
When NetLabel is not enabled, e.g. CONFIG_NETLABEL=n, and the system receives a CIPSO tagged packet it is dropped (cipso_v4_validate() returns non-zero). In most cases this is the correct and desired behavior, however, in the case where we are simply forwarding the traffic, e.g. acting as a network bridge, this becomes a problem. This patch fixes the forwarding problem by providing the basic CIPSO validation code directly in ip_options_compile() without the need for the NetLabel or CIPSO code. The new validation code can not perform any of the CIPSO option label/value verification that cipso_v4_validate() does, but it can verify the basic CIPSO option format. The behavior when NetLabel is enabled is unchanged. Signed-off-by: Paul Moore <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cc9b17a commit 20e2a86

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

include/net/cipso_ipv4.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <net/netlabel.h>
4343
#include <net/request_sock.h>
4444
#include <linux/atomic.h>
45+
#include <asm/unaligned.h>
4546

4647
/* known doi values */
4748
#define CIPSO_V4_DOI_UNKNOWN 0x00000000
@@ -285,7 +286,33 @@ static inline int cipso_v4_skbuff_getattr(const struct sk_buff *skb,
285286
static inline int cipso_v4_validate(const struct sk_buff *skb,
286287
unsigned char **option)
287288
{
288-
return -ENOSYS;
289+
unsigned char *opt = *option;
290+
unsigned char err_offset = 0;
291+
u8 opt_len = opt[1];
292+
u8 opt_iter;
293+
294+
if (opt_len < 8) {
295+
err_offset = 1;
296+
goto out;
297+
}
298+
299+
if (get_unaligned_be32(&opt[2]) == 0) {
300+
err_offset = 2;
301+
goto out;
302+
}
303+
304+
for (opt_iter = 6; opt_iter < opt_len;) {
305+
if (opt[opt_iter + 1] > (opt_len - opt_iter)) {
306+
err_offset = opt_iter + 1;
307+
goto out;
308+
}
309+
opt_iter += opt[opt_iter + 1];
310+
}
311+
312+
out:
313+
*option = opt + err_offset;
314+
return err_offset;
315+
289316
}
290317
#endif /* CONFIG_NETLABEL */
291318

0 commit comments

Comments
 (0)