Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3925386imm; Mon, 8 Oct 2018 11:47:24 -0700 (PDT) X-Google-Smtp-Source: ACcGV63qGFj5B84R92SWYrZkHvVwWahTI/KIJUd9ToDe6gJ/IVyVXCRo0gXs+pGAQqJOJtBnvw6x X-Received: by 2002:a17:902:286b:: with SMTP id e98-v6mr25059072plb.110.1539024444937; Mon, 08 Oct 2018 11:47:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539024444; cv=none; d=google.com; s=arc-20160816; b=xUaEInumrr7+zhhxhC55q80WgPcqMnW9ZDDVFxzpwzKSuDtjAwp2hQJYr5/wNOfKW/ vr44NhTcWUWA8LYuGysvMt5utvf+v8es5Zp2lMOBAGA1EIrdYn0kr4XrNRQH9LjdcGtm 78o5Fy+wc1c2zoeiofW1ToWvqDmtcsuWbuSh6g+QQJcqU+YttJKitxenD/hMmS9Tv+/x 4JspOP2dOhP2CvpZPK/TLj5W1o0EkxVrIIFkP4bmsITfnS2XY2ksi+THVlPJhTvbI8cb d6t7E1Uih3T4cZjh5NZYuR1IkH1zPGk68z7+g7l4qU9m4LiVjm11mTalGyDUiL3YuE/b 7n1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SVIm0BDuptpMvEmHEgTjrbRQsZ9q+mVSqtr2Lor+c4Q=; b=M74AYIRL0ZhH267RdF7zkRoCJ1y4yRLZAQD6g1hVMOu01y1NC2nhQqaTPpYDo3li7Z nX9TbBoFJbWpLNRhsGmrjaF3xpuzSJwr8TbpLWy/1/u0PGdNd5eCY7wDxJ5k1ByUqiFD wzHM6aK1O3jkXAHs2ObOZdYpyYZTo9YUvXH1PjRHV5uD0QuNVRR/IzqED+HoDrmphieH s5FRXrEdxvZEDhpdpaCxB9wWYH7Nm5lw3DVlutZ1V7aLLu93njYjMADTNhAqICI6mS/C pfmkUnWcE5tZUudtx4YJ2JuaiQQmQbGPZTjRPeaohSpFvspONDrmhCpJNFModw23guMA 3LRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uPvuemjX; 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 b11-v6si20987863plk.302.2018.10.08.11.47.10; Mon, 08 Oct 2018 11:47:24 -0700 (PDT) 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=@kernel.org header.s=default header.b=uPvuemjX; 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 S1731284AbeJIB77 (ORCPT + 99 others); Mon, 8 Oct 2018 21:59:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:48290 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727510AbeJIB77 (ORCPT ); Mon, 8 Oct 2018 21:59:59 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4456721479; Mon, 8 Oct 2018 18:46:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024412; bh=xo/S2Fwp4pTP/WIoom9cLdR3OtD7UoW87lKcBbgYcks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uPvuemjXPOzqhqcpX9+oqvBbQEZZKG18D/dnh3Ihbb7EWDvMlrlguwGW8RH2zsS6l q4kHE4J0eAXPxIrjrY6QOYLyqH+1W3K1F/EfmXgONT3xqKu275LPYbxOUFW/ySlTgA 9vVCkmfA88ZkVBpa1z5LO369QYETC1nVY7NJvtVY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , John Fastabend , Alexei Starovoitov , Sasha Levin Subject: [PATCH 4.18 030/168] bpf: fix sg shift repair start offset in bpf_msg_pull_data Date: Mon, 8 Oct 2018 20:30:10 +0200 Message-Id: <20181008175621.194130044@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Borkmann [ Upstream commit a8cf76a9023bc6709b1361d06bb2fae5227b9d68 ] When we perform the sg shift repair for the scatterlist ring, we currently start out at i = first_sg + 1. However, this is not correct since the first_sg could point to the sge sitting at slot MAX_SKB_FRAGS - 1, and a subsequent i = MAX_SKB_FRAGS will access the scatterlist ring (sg) out of bounds. Add the sk_msg_iter_var() helper for iterating through the ring, and apply the same rule for advancing to the next ring element as we do elsewhere. Later work will use this helper also in other places. Fixes: 015632bb30da ("bpf: sk_msg program helper bpf_sk_msg_pull_data") Signed-off-by: Daniel Borkmann Acked-by: John Fastabend Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/core/filter.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2272,6 +2272,13 @@ static const struct bpf_func_proto bpf_m .arg2_type = ARG_ANYTHING, }; +#define sk_msg_iter_var(var) \ + do { \ + var++; \ + if (var == MAX_SKB_FRAGS) \ + var = 0; \ + } while (0) + BPF_CALL_4(bpf_msg_pull_data, struct sk_msg_buff *, msg, u32, start, u32, end, u64, flags) { @@ -2292,9 +2299,7 @@ BPF_CALL_4(bpf_msg_pull_data, if (start < offset + len) break; offset += len; - i++; - if (i == MAX_SKB_FRAGS) - i = 0; + sk_msg_iter_var(i); } while (i != msg->sg_end); if (unlikely(start >= offset + len)) @@ -2320,9 +2325,7 @@ BPF_CALL_4(bpf_msg_pull_data, */ do { copy += sg[i].length; - i++; - if (i == MAX_SKB_FRAGS) - i = 0; + sk_msg_iter_var(i); if (bytes_sg_total <= copy) break; } while (i != msg->sg_end); @@ -2348,9 +2351,7 @@ BPF_CALL_4(bpf_msg_pull_data, sg[i].length = 0; put_page(sg_page(&sg[i])); - i++; - if (i == MAX_SKB_FRAGS) - i = 0; + sk_msg_iter_var(i); } while (i != last_sg); sg[first_sg].length = copy; @@ -2367,7 +2368,8 @@ BPF_CALL_4(bpf_msg_pull_data, if (!shift) goto out; - i = first_sg + 1; + i = first_sg; + sk_msg_iter_var(i); do { int move_from; @@ -2384,9 +2386,7 @@ BPF_CALL_4(bpf_msg_pull_data, sg[move_from].page_link = 0; sg[move_from].offset = 0; - i++; - if (i == MAX_SKB_FRAGS) - i = 0; + sk_msg_iter_var(i); } while (1); msg->sg_end -= shift; if (msg->sg_end < 0)