Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp535385img; Tue, 26 Feb 2019 04:31:52 -0800 (PST) X-Google-Smtp-Source: AHgI3IbOGE7BpSBs8ej613/yHmdXEoVOELdsXYQgDqIZg4nS8grzCiR7CHqxzuhAht/aZ/ccamcR X-Received: by 2002:a65:5303:: with SMTP id m3mr12705699pgq.292.1551184312041; Tue, 26 Feb 2019 04:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551184312; cv=none; d=google.com; s=arc-20160816; b=pRG6mGBV0COq1p1IlPd7I4g1xPwD1onvMm0BWLPajGXF+r25QNy886fQmEcNAaINkl dq7uF1fiIGB7FA0d5FRot+DVEvvgCuZwLq3C/7pQ4fy6SZp9gSP7WpgbEJ+YS/NYk4Wp E5qqZ4vJVTWZqzNcMRVijoMeTuxWdeDe+WYBwnZhpl0c+e6vv2DRJK7vdfHNwb0AR0wN zA8POhGholAQT/sAySHY3um1vy+p6xXkt6Rieg2ou4y6hdlb4elVI1cuxyfHyKGxNAzS btBCP3hJYVry7YWWeEqOt6X6OQbAMuUJvzuSBx62/epzkDf4kyyKpVb0jecdnz2P/U7a f3Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=N9u+Jv5uWG6cdhcjH1Bzt8ABpt2pO+Zie2czOpblcgA=; b=n64TgB+lURi12H5ydGZd9N+Fvx/goWQhFVgUGZ3+ZyMq+Z86dm04CHiPM/Wt/hLPwJ mJWExQp8R5Hxwl3D+rYg3xu8hD2ntTw0oS9powG6UCMtEL4GN4zmOMyBktjrdX8gvXhW KQx0DEzHAsq43dMCdYMbTTCpE/MY6b3g1BXBINr8zEvF0Q8o5EJG02SzfCNbRuy3l2DF RQEtaCfYVekA8ltTShEYWuKjCyUJlB0ID5TKmOGdGC2m/lB/bw+8yZ1ofkrwCXobZGyc IvjUp8a5Qn4wDgnpknkggcYz+N6yUL0cbEFaX2yE9V3a7pZnt/CZ6Q4C7e0H9cJLKwXU 4hPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b15si12381392pfm.72.2019.02.26.04.31.36; Tue, 26 Feb 2019 04:31:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726881AbfBZM3w (ORCPT + 99 others); Tue, 26 Feb 2019 07:29:52 -0500 Received: from charlotte.tuxdriver.com ([70.61.120.58]:42007 "EHLO smtp.tuxdriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726346AbfBZM3w (ORCPT ); Tue, 26 Feb 2019 07:29:52 -0500 Received: from cpe-2606-a000-111b-405a-9816-2c85-c514-8f7a.dyn6.twc.com ([2606:a000:111b:405a:9816:2c85:c514:8f7a] helo=localhost) by smtp.tuxdriver.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1gybrd-0005bU-11; Tue, 26 Feb 2019 07:29:42 -0500 Date: Tue, 26 Feb 2019 07:29:02 -0500 From: Neil Horman To: Xin Long Cc: LKML , network dev , linux-sctp@vger.kernel.org, davem , Marcelo Ricardo Leitner Subject: Re: [PATCH net] sctp: get sctphdr by offset in sctp_compute_cksum Message-ID: <20190226122902.GA13064@hmswarspite.think-freely.org> References: <2aee76766861ac9e46b7acf123d5d6e8f2adf8e0.1551093937.git.lucien.xin@gmail.com> <20190225124614.GB30699@hmswarspite.think-freely.org> <20190225140720.GC30699@hmswarspite.think-freely.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) X-Spam-Score: -2.9 (--) X-Spam-Status: No Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 26, 2019 at 12:15:54AM +0800, Xin Long wrote: > On Mon, Feb 25, 2019 at 10:08 PM Neil Horman wrote: > > > > On Mon, Feb 25, 2019 at 09:20:44PM +0800, Xin Long wrote: > > > On Mon, Feb 25, 2019 at 8:47 PM Neil Horman wrote: > > > > > > > > On Mon, Feb 25, 2019 at 07:25:37PM +0800, Xin Long wrote: > > > > > sctp_hdr(skb) only works when skb->transport_header is set properly. > > > > > > > > > > But in the path of nf_conntrack_in: sctp_packet() -> sctp_error() > > > > > > > > > > skb->transport_header is not guaranteed to be right value for sctp. > > > > > It will cause to fail to check the checksum for sctp packets. > > > > > > > > > > So fix it by using offset, which is always right in all places. > > > > > > > > > > Fixes: e6d8b64b34aa ("net: sctp: fix and consolidate SCTP checksumming code") > > > > > Reported-by: Li Shuang > > > > > Signed-off-by: Xin Long > > > > > --- > > > > > include/net/sctp/checksum.h | 2 +- > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > > diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h > > > > > index 32ee65a..1c6e6c0 100644 > > > > > --- a/include/net/sctp/checksum.h > > > > > +++ b/include/net/sctp/checksum.h > > > > > @@ -61,7 +61,7 @@ static inline __wsum sctp_csum_combine(__wsum csum, __wsum csum2, > > > > > static inline __le32 sctp_compute_cksum(const struct sk_buff *skb, > > > > > unsigned int offset) > > > > > { > > > > > - struct sctphdr *sh = sctp_hdr(skb); > > > > > + struct sctphdr *sh = (struct sctphdr *)(skb->data + offset); > > > > > const struct skb_checksum_ops ops = { > > > > > .update = sctp_csum_update, > > > > > .combine = sctp_csum_combine, > > > > > -- > > > > > 2.1.0 > > > > > > > > > > > > > > Shouldn't you use skb_set_transport_header and skb_transport_header here? > > > you mean: > > > skb_set_transport_header(skb, offset); > > > sh = sctp_hdr(skb); > > > ? > > > > > > There's no place counting on here to set transport_header. > > > It will be a kinda redundant job, yet skb is 'const'. > > > > > I'm not sure what you mean by "theres no place counting here". We have the > > transport header offset, and you're doing the exact same computation that that > > function does. It seems like we should use it in case the underlying > > implementation changes. > 1. skb_set_transport_header() and sctp_hdr() are like: > skb->transport_header = skb->data - skb->head; > skb->transport_header += offset > sh = skb->head + skb->transport_header; > > 2. in this patch: > sh = (struct sctphdr *)(skb->data + offset); only > > I think the 2nd one is better. > > I feel it's weird to set transport_header here if it's only for > sctp_hdr(skb) in here. > > As for "underlying implementation changes", I don't know exactly the case > but there are quite a few places doing things like: > *hdr = (struct *hdr *)(skb->data + hdroff); > > I'd think it's safe. no? > Safe, yes, it just doesn't seem right. I know you've pointed out several places below that rapidly compute transport offsets in a one-off fashion, but at this same time, the other primary transports (tcp and udp), all seems to use the transport header to do their work (linearizing as necessecary, which sctp also does in sctp_rcv, at least in most cases). > > > > I understand what you are saying regarding the use of a const variable there, > > but perhaps thats an argument for removing the const storage classifier. Better > > still, it would be good to figure out why all paths to this function don't > > already set the transport header offset to begin with (addressing your redundant > > comment) > The issue was reported when going to nf_conntrack by br_netfilter's > bridge-nf-call-iptables. > As you can see on nf_conntrack_in() path, even iphdr is got by: > iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph); > It's impossible to set skb->transport_header when we're not sure iphdr > in linearized memory. > But if the skb isn't linearized, computing the transport header manually isn't going to help you anyway. You can see that in skb_header_pointer. If the offset they are trying to get to is outside the bounds of the length of the skb (i.e. the fragmented case), it calls skb_copy_bits to linearize the needed segment. It seems we should be doing something simmilar. In most cases we are already linearized from sctp_rcv (possibly all, I need to think about that). All I'm really saying is that by using the skb apis we insulate ourselves from potential changes in how skbs might work in the future. I'm not strictly bound to setting the transport header, but we should definately be getting the transport header via the skb utility functions wherever possible. Neil