Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4635697imc; Mon, 25 Feb 2019 08:17:08 -0800 (PST) X-Google-Smtp-Source: AHgI3Ia1h2jZG8vHs6AYOCHP3Zjc9otm/6BRt1dV0BQ3o92PrN2B8Os02ZawohQrxTEsnZLw0/sV X-Received: by 2002:a62:ab04:: with SMTP id p4mr21143075pff.142.1551111428544; Mon, 25 Feb 2019 08:17:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551111428; cv=none; d=google.com; s=arc-20160816; b=htuFxwp7Yx9N5A7kIfn9jhfHlXmQEbhDe3KAMBi0XwEwv0hPsMVQkatMQUpjkQJiFv aggzsENoi40ugZx7/2mpSIZBqxquLX1mJcLVpA1nKmmP74bjmfqTaJaGz89o+JBpJpcp ktHJ79qdzE6VIc/z49oM63tYwyhgC6EBqnzATTe3Xg8zzdLYV9u/t4gcZxwYRXYMmo0r NCBVRewE2GuYBpz9v46x42IhiH212MhXVSKIxD+T71VN6i09Z3kUtZlpTY2P4+a77hi4 krn6MOmOJVF0h6fZtpufWkNZCngX0BlDg3K5EpV/xh9Wx7bA2/ELdvEsD/9AJ4rUDgRy NjKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=X4mbrf4hSifC2rI+Ol4ZYxxZi3/Gzwo7T+9roZ/nN68=; b=NYXk2TBIAjjkep/+Ss3hnJYEaXKJMmAQAGCdZN5FFKXg2x7+gCfJ0+k8dvxLboX4WE lw2wP5jrXtdZKadSwk5ld5OOx70xM+PQqzUcymT9rl/sVTMorhAKOYLlHt0W2z4ReBfa f6xQEUss++I5nA3btJ9uFIXqDX9I0tJmEETblzpbEuxvZIh2hjsGI1S26xNAUuOJkpC2 mD/LUPSrRD4HJgYbx4peaESJXu4BFi56yLBTALJxHOWioiydj506h6WNIGXzmgXuqKP9 NoXuE+yvx5SqWg4nBDEMJWutfpRkjdBUiPMei1zmAZj48ms6yN4ogzUoyOI+FW+mtOLS hauQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mrtQ2Ttw; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g20si10060680pgk.587.2019.02.25.08.16.53; Mon, 25 Feb 2019 08:17:08 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mrtQ2Ttw; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728141AbfBYQQI (ORCPT + 99 others); Mon, 25 Feb 2019 11:16:08 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36536 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727684AbfBYQQI (ORCPT ); Mon, 25 Feb 2019 11:16:08 -0500 Received: by mail-wr1-f66.google.com with SMTP id o17so10603379wrw.3; Mon, 25 Feb 2019 08:16:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=X4mbrf4hSifC2rI+Ol4ZYxxZi3/Gzwo7T+9roZ/nN68=; b=mrtQ2Ttw0HcE1W54Ve/6MNuzN21yABzQvfS/uq95+5TK5nJj8I1dtR3x1MGCHv4K0X EmyGuSFzFaszfGAB7/4OrRi/AFNyreywM1cNyh0GFhEdjUDULkvYT+FHh5UY5iL+b8KG k05XdPrFbmoF1i23Uvgahzb2P9wuPpjmj50gA+fMQQZSdpj2LV2wBwZjAz29dvuG+6qO 3GLlCRNsrEU3p23Bn1XTbJYmP2pQaVbCJISEfkWrA9duV/R+CGMskKmZ0cVZcJhAhr7s SmpWZZkUtu/98HDl2RXe/Omi483SPUCySbkIl+4tVW4tZS5Nl5XE+E+nBUFxB4V0s1hs x5xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=X4mbrf4hSifC2rI+Ol4ZYxxZi3/Gzwo7T+9roZ/nN68=; b=E+wjy5lU0BLNDyHa4h4GB5gJhh+JAkm5N532L5io5v4ysFls0jLOiQ+thDmSZzB40l FerQhqQ9a7e4RkkH9Jg7uWH2FNtu14MJML/wX8iWy9s6Pincml3Jw1keEIvoLORGIq9L aNI8YpWHZZnd3ULUCsn1dilJfePoOW2sYnD+D8l68dNmlm4pEKQwsiqmLYHDYA0ub6WV oT7D+nwDykrtjbJJItdFo7PmKJL/mmJs7dyV0zyN4IvTciasWP3+2nhkjmnOgS+m4iUA D9ZG65X8D5wZCXoIlGMnqtEFarDjd0UnqniMrf61QyiPGq0kNwa4DwmIEIesoosGozCk FKGQ== X-Gm-Message-State: AHQUAuYP/UdPRRPC6m0WLEp52cnpKaxOZXI0ecMj3CRdrFsNHExqNkCf LferCYD98qZMWe/6krnyhg2m3oq0wzuAVz5YJaQ= X-Received: by 2002:a5d:6288:: with SMTP id k8mr14024402wru.173.1551111365600; Mon, 25 Feb 2019 08:16:05 -0800 (PST) MIME-Version: 1.0 References: <2aee76766861ac9e46b7acf123d5d6e8f2adf8e0.1551093937.git.lucien.xin@gmail.com> <20190225124614.GB30699@hmswarspite.think-freely.org> <20190225140720.GC30699@hmswarspite.think-freely.org> In-Reply-To: <20190225140720.GC30699@hmswarspite.think-freely.org> From: Xin Long Date: Tue, 26 Feb 2019 00:15:54 +0800 Message-ID: Subject: Re: [PATCH net] sctp: get sctphdr by offset in sctp_compute_cksum To: Neil Horman Cc: LKML , network dev , linux-sctp@vger.kernel.org, davem , Marcelo Ricardo Leitner Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > > 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.