From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Miller Subject: Re: [bpf PATCH 2/3] bpf: sockmap, zero sg_size on error when buffer is released Date: Wed, 02 May 2018 14:51:45 -0400 (EDT) Message-ID: <20180502.145145.2220259739563330693.davem@davemloft.net> References: <20180502173954.17875.19624.stgit@john-Precision-Tower-5810> <20180502174732.17875.75344.stgit@john-Precision-Tower-5810> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: borkmann@iogearbox.net, ast@kernel.org, netdev@vger.kernel.org To: john.fastabend@gmail.com Return-path: Received: from shards.monkeyblade.net ([184.105.139.130]:36124 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751087AbeEBSvq (ORCPT ); Wed, 2 May 2018 14:51:46 -0400 In-Reply-To: <20180502174732.17875.75344.stgit@john-Precision-Tower-5810> Sender: netdev-owner@vger.kernel.org List-ID: From: John Fastabend Date: Wed, 02 May 2018 10:47:32 -0700 > When an error occurs during a redirect we have two cases that need > to be handled (i) we have a cork'ed buffer (ii) we have a normal > sendmsg buffer. > > In the cork'ed buffer case we don't currently support recovering from > errors in a redirect action. So the buffer is released and the error > should _not_ be pushed back to the caller of sendmsg/sendpage. The > rationale here is the user will get an error that relates to old > data that may have been sent by some arbitrary thread on that sock. > Instead we simple consume the data and tell the user that the data > has been consumed. We may add proper error recovery in the future. > However, this patch fixes a bug where the bytes outstanding counter > sg_size was not zeroed. This could result in a case where if the user > has both a cork'ed action and apply action in progress we may > incorrectly call into the BPF program when the user expected an > old verdict to be applied via the apply action. I don't have a use > case where using apply and cork at the same time is valid but we > never explicitly reject it because it should work fine. This patch > ensures the sg_size is zeroed so we don't have this case. > > In the normal sendmsg buffer case (no cork data) we also do not > zero sg_size. Again this can confuse the apply logic when the logic > calls into the BPF program when the BPF programmer expected the old > verdict to remain. So ensure we set sg_size to zero here as well. And > additionally to keep the psock state in-sync with the sk_msg_buff > release all the memory as well. Previously we did this before > returning to the user but this left a gap where psock and sk_msg_buff > states were out of sync which seems fragile. No additional overhead > is taken here except for a call to check the length and realize its > already been freed. This is in the error path as well so in my > opinion lets have robust code over optimized error paths. > > Signed-off-by: John Fastabend Acked-by: David S. Miller