@@ -73,13 +73,13 @@ struct rfc2734_header {
73
73
74
74
#define fwnet_get_hdr_lf (h ) (((h)->w0 & 0xc0000000) >> 30)
75
75
#define fwnet_get_hdr_ether_type (h ) (((h)->w0 & 0x0000ffff))
76
- #define fwnet_get_hdr_dg_size (h ) (((h)->w0 & 0x0fff0000) >> 16)
76
+ #define fwnet_get_hdr_dg_size (h ) (((( h)->w0 & 0x0fff0000) >> 16) + 1 )
77
77
#define fwnet_get_hdr_fg_off (h ) (((h)->w0 & 0x00000fff))
78
78
#define fwnet_get_hdr_dgl (h ) (((h)->w1 & 0xffff0000) >> 16)
79
79
80
- #define fwnet_set_hdr_lf (lf ) ((lf) << 30)
80
+ #define fwnet_set_hdr_lf (lf ) ((lf) << 30)
81
81
#define fwnet_set_hdr_ether_type (et ) (et)
82
- #define fwnet_set_hdr_dg_size (dgs ) ((dgs) << 16)
82
+ #define fwnet_set_hdr_dg_size (dgs ) ((( dgs) - 1 ) << 16)
83
83
#define fwnet_set_hdr_fg_off (fgo ) (fgo)
84
84
85
85
#define fwnet_set_hdr_dgl (dgl ) ((dgl) << 16)
@@ -591,6 +591,9 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len,
591
591
int retval ;
592
592
u16 ether_type ;
593
593
594
+ if (len <= RFC2374_UNFRAG_HDR_SIZE )
595
+ return 0 ;
596
+
594
597
hdr .w0 = be32_to_cpu (buf [0 ]);
595
598
lf = fwnet_get_hdr_lf (& hdr );
596
599
if (lf == RFC2374_HDR_UNFRAG ) {
@@ -615,7 +618,12 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len,
615
618
return fwnet_finish_incoming_packet (net , skb , source_node_id ,
616
619
is_broadcast , ether_type );
617
620
}
621
+
618
622
/* A datagram fragment has been received, now the fun begins. */
623
+
624
+ if (len <= RFC2374_FRAG_HDR_SIZE )
625
+ return 0 ;
626
+
619
627
hdr .w1 = ntohl (buf [1 ]);
620
628
buf += 2 ;
621
629
len -= RFC2374_FRAG_HDR_SIZE ;
@@ -627,7 +635,10 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len,
627
635
fg_off = fwnet_get_hdr_fg_off (& hdr );
628
636
}
629
637
datagram_label = fwnet_get_hdr_dgl (& hdr );
630
- dg_size = fwnet_get_hdr_dg_size (& hdr ); /* ??? + 1 */
638
+ dg_size = fwnet_get_hdr_dg_size (& hdr );
639
+
640
+ if (fg_off + len > dg_size )
641
+ return 0 ;
631
642
632
643
spin_lock_irqsave (& dev -> lock , flags );
633
644
@@ -735,6 +746,22 @@ static void fwnet_receive_packet(struct fw_card *card, struct fw_request *r,
735
746
fw_send_response (card , r , rcode );
736
747
}
737
748
749
+ static int gasp_source_id (__be32 * p )
750
+ {
751
+ return be32_to_cpu (p [0 ]) >> 16 ;
752
+ }
753
+
754
+ static u32 gasp_specifier_id (__be32 * p )
755
+ {
756
+ return (be32_to_cpu (p [0 ]) & 0xffff ) << 8 |
757
+ (be32_to_cpu (p [1 ]) & 0xff000000 ) >> 24 ;
758
+ }
759
+
760
+ static u32 gasp_version (__be32 * p )
761
+ {
762
+ return be32_to_cpu (p [1 ]) & 0xffffff ;
763
+ }
764
+
738
765
static void fwnet_receive_broadcast (struct fw_iso_context * context ,
739
766
u32 cycle , size_t header_length , void * header , void * data )
740
767
{
@@ -744,9 +771,6 @@ static void fwnet_receive_broadcast(struct fw_iso_context *context,
744
771
__be32 * buf_ptr ;
745
772
int retval ;
746
773
u32 length ;
747
- u16 source_node_id ;
748
- u32 specifier_id ;
749
- u32 ver ;
750
774
unsigned long offset ;
751
775
unsigned long flags ;
752
776
@@ -763,22 +787,17 @@ static void fwnet_receive_broadcast(struct fw_iso_context *context,
763
787
764
788
spin_unlock_irqrestore (& dev -> lock , flags );
765
789
766
- specifier_id = (be32_to_cpu (buf_ptr [0 ]) & 0xffff ) << 8
767
- | (be32_to_cpu (buf_ptr [1 ]) & 0xff000000 ) >> 24 ;
768
- ver = be32_to_cpu (buf_ptr [1 ]) & 0xffffff ;
769
- source_node_id = be32_to_cpu (buf_ptr [0 ]) >> 16 ;
770
-
771
- if (specifier_id == IANA_SPECIFIER_ID &&
772
- (ver == RFC2734_SW_VERSION
790
+ if (length > IEEE1394_GASP_HDR_SIZE &&
791
+ gasp_specifier_id (buf_ptr ) == IANA_SPECIFIER_ID &&
792
+ (gasp_version (buf_ptr ) == RFC2734_SW_VERSION
773
793
#if IS_ENABLED (CONFIG_IPV6 )
774
- || ver == RFC3146_SW_VERSION
794
+ || gasp_version ( buf_ptr ) == RFC3146_SW_VERSION
775
795
#endif
776
- )) {
777
- buf_ptr += 2 ;
778
- length -= IEEE1394_GASP_HDR_SIZE ;
779
- fwnet_incoming_packet ( dev , buf_ptr , length , source_node_id ,
796
+ ))
797
+ fwnet_incoming_packet ( dev , buf_ptr + 2 ,
798
+ length - IEEE1394_GASP_HDR_SIZE ,
799
+ gasp_source_id ( buf_ptr ) ,
780
800
context -> card -> generation , true);
781
- }
782
801
783
802
packet .payload_length = dev -> rcv_buffer_size ;
784
803
packet .interrupt = 1 ;
0 commit comments