Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3926221imm; Mon, 8 Oct 2018 11:48:23 -0700 (PDT) X-Google-Smtp-Source: ACcGV63HRYajwq6AClGExngNmSpRJdGuKmsmyx64okQpDZoS8oUQLHNe00ISV4UlsfPxSVKoPsja X-Received: by 2002:a17:902:1021:: with SMTP id b30-v6mr25617827pla.23.1539024502966; Mon, 08 Oct 2018 11:48:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539024502; cv=none; d=google.com; s=arc-20160816; b=bvSecWPtTS+Nwb0Ct5ujeJxIls2ADg7V8MKXHYv0R9BKTzkEpHfoMEk9DADXaJ15JU VSu77JJYBC1IjNOjE8Wh4tFeOLGYlfXUd6hMP3JYdRfpokXFCFqgXPWeZS4Dh1Bdmddr eel1S7KvbjvDKyq/Ly7lnXdYaWt7ZLIFOa/rFYppexezp1yFAqpHwLCMASYvp1w8XMsq MLlU0bZIUs3sNAjYHOmb6VEhMSzsxnx5S37NeqneXym7s9XtDsMUEQp23wum6KZkcy1a 3QdJNbdYzdGuYp5gDHmAZ/MBwkAWsF8xHZ7PlPHYw3MgHX0f9DtPwvtKKBBbZOi6Nxit qgtA== 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=s4aUOhZBA7zEttEur1ETv/0yUTZNQNrpOuUDJW3b+/I=; b=UKtIbHYXNSiKZh6osAxERi12b2gifa9WAavHRLIY/6tjYQ/LRKxLBZpAYXUl5Da7s6 65eTjwfMubbSO4HgD8yhnFAmmagpjZePCuz55fkl2pEdhBQ7cqbXsxAE9V1Gs5IYLcvO g/PxoCI831QyvXz5iQde6Dt5DgG1w3zaWbjOsXtT02ZvLcIChnQ7MPKM4PibqSVO68Gy +L0WQmuqqFk4ZvswJOfP8JFT8pAuwZLk7Q4gzQNliuH3CLMomxHr5jp3hEpVszp/jMno MKT8qBxSoeUpqOgVsMExJwSWJuufo6YUrZf89XGsZhbg2P55TehpLO+0Jjr4lXzPm6kF bf5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SK+MHcPM; 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 g17-v6si18409915pfo.130.2018.10.08.11.48.07; Mon, 08 Oct 2018 11:48:22 -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=SK+MHcPM; 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 S1731543AbeJICBA (ORCPT + 99 others); Mon, 8 Oct 2018 22:01:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:49876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728239AbeJICA7 (ORCPT ); Mon, 8 Oct 2018 22:00: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 3F68D204FD; Mon, 8 Oct 2018 18:47:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024472; bh=2FHM7imDNLwTlUppCa6ZvIYx3O+BSlvO5RCQt+Ly+F4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SK+MHcPMv4r+NowG2FWQc3IyhggkGvx/kLqsVD3mdpL+uJAdJ1jciEYZxxmRCV7zc rl3ztdCgJSWXrybZCROL+/vJGJerTep0iIOdhMYAUVlxH1A/XlZGiIBh/QHgyUVhQx u8Cuv26TmM2WDSDeEdugor5LuuGKD8TSA/2nIzcE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tushar Dave , Daniel Borkmann , Sasha Levin Subject: [PATCH 4.18 051/168] bpf: Fix bpf_msg_pull_data() Date: Mon, 8 Oct 2018 20:30:31 +0200 Message-Id: <20181008175621.993081117@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: Tushar Dave [ Upstream commit 9db39f4d4f94b61e4b64b077f6ddb2bdfb533a88 ] Helper bpf_msg_pull_data() mistakenly reuses variable 'offset' while linearizing multiple scatterlist elements. Variable 'offset' is used to find first starting scatterlist element i.e. msg->data = sg_virt(&sg[first_sg]) + start - offset" Use different variable name while linearizing multiple scatterlist elements so that value contained in variable 'offset' won't get overwritten. Fixes: 015632bb30da ("bpf: sk_msg program helper bpf_sk_msg_pull_data") Signed-off-by: Tushar Dave Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/core/filter.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2282,7 +2282,7 @@ static const struct bpf_func_proto bpf_m BPF_CALL_4(bpf_msg_pull_data, struct sk_msg_buff *, msg, u32, start, u32, end, u64, flags) { - unsigned int len = 0, offset = 0, copy = 0; + unsigned int len = 0, offset = 0, copy = 0, poffset = 0; int bytes = end - start, bytes_sg_total; struct scatterlist *sg = msg->sg_data; int first_sg, last_sg, i, shift; @@ -2338,16 +2338,15 @@ BPF_CALL_4(bpf_msg_pull_data, if (unlikely(!page)) return -ENOMEM; p = page_address(page); - offset = 0; i = first_sg; do { from = sg_virt(&sg[i]); len = sg[i].length; - to = p + offset; + to = p + poffset; memcpy(to, from, len); - offset += len; + poffset += len; sg[i].length = 0; put_page(sg_page(&sg[i]));