From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B45D1A0613 for ; Tue, 30 Jul 2019 19:27:48 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A1E841BFCE; Tue, 30 Jul 2019 19:27:46 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id CB0C91BF12; Tue, 30 Jul 2019 19:27:44 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4675308A958; Tue, 30 Jul 2019 17:27:43 +0000 (UTC) Received: from dhcp-25.97.bos.redhat.com (unknown [10.18.25.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5937719C5B; Tue, 30 Jul 2019 17:27:42 +0000 (UTC) From: Aaron Conole To: Ferruh Yigit Cc: Adrien Mazarguil , David Marchand , Bernard Iremonger , dev , dpdk stable , Thomas Monjalon , "Singh\, Jasvinder" , Flavia Musatescu References: <1562670596-27129-1-git-send-email-bernard.iremonger@intel.com> <10372251.KTS5ePcUbj@xps> <20190730161831.GE4512@6wind.com> Date: Tue, 30 Jul 2019 13:27:41 -0400 In-Reply-To: (Ferruh Yigit's message of "Tue, 30 Jul 2019 17:35:28 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 30 Jul 2019 17:27:44 +0000 (UTC) Subject: Re: [dpdk-dev] [dpdk-stable] [PATCH] librte_flow_classify: fix out-of-bounds access X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Ferruh Yigit writes: > On 7/30/2019 5:18 PM, Adrien Mazarguil wrote: >> On Tue, Jul 30, 2019 at 03:48:31PM +0100, Ferruh Yigit wrote: >>> On 7/30/2019 3:42 PM, Aaron Conole wrote: >>>> David Marchand writes: >>>> >>>>> On Wed, Jul 10, 2019 at 11:49 PM Thomas Monjalon wrote: >>>>>> >>>>>> 09/07/2019 13:09, Bernard Iremonger: >>>>>>> This patch fixes the out-of-bounds coverity issue by removing the >>>>>>> offending line of code at line 107 in rte_flow_classify_parse.c >>>>>>> which is never executed. >>>>>>> >>>>>>> Coverity issue: 343454 >>>>>>> >>>>>>> Fixes: be41ac2a330f ("flow_classify: introduce flow classify library") >>>>>>> Cc: stable@dpdk.org >>>>>>> Signed-off-by: Bernard Iremonger >>>>>> >>>>>> Applied, thanks >>>>> >>>>> We have a segfault in the unit tests since this patch. >>>> >>>> I think this patch is still correct. The issue is in the semantic of >>>> the flow classify pattern. It *MUST* always have a valid end marker, >>>> but the test passes an invalid end marker. This causes the bounds to >>>> exceed. >>>> >>>> So, it would be best to fix it, either by having a "failure" on unknown >>>> markers (f.e. -1), or by passing a length around. However, the crash >>>> should be expected. The fact that the previous code was also incorrect >>>> and resulted in no segfault is pure luck. >>>> >>>> See rte_flow_classify_parse.c:80 and test_flow_classify.c:387 >>>> >>>> I would be in favor of passing the lengths of the two arrays to these >>>> APIs. That would let us still make use of the markers (for valid >>>> construction), but also let us reason about lengths in a sane way. >>>> >>>> WDYT? >>>> >>> >>> +1, I also just replied with something very similar. >>> >>> With current API the testcase is wrong, and it will crash, also the invalid >>> action one has exact same problem. >>> >>> The API can be updated as you suggested, with a length field and testcases can >>> be added back. >>> >>> What worries me more is the rte_flow, which uses same arguments, and open to >>> same errors, should we consider updating rte_flow APIs to have lengths values too? >> >> (Jumping in since all dashboard lights in my control room went red after >> "rte_flow" was detected in this discussion) > > :) > >> >> Length values for patterns and action lists were considered during design >> but END was preferred as the better solution for convenience and because >> it's actually safer: >> >> - C programmers are well aware of the dire consequences of omitting the >> ending NUL byte in strings so it's not a foreign concept. This is >> documented as such for rte_flow. > > I believe, C string functions are one of the most error prone part of the libc, > even after a dozen of years it is not rare to crash the applications because of > omitted terminating NULL, so I think this is not the best example :) +1 >> >> - Static initialization of flow rules (i.e. defining a large fixed array) >> is much easier if one doesn't have to encode its size as well, think about >> compilation directives (#ifdef) on some of its elements. >> >> - Like omitting the END element, providing the wrong array size by mistake >> remains a possibility, with similar or possibly worse consequences as >> it's less likely to crash early and more prone to silent data corruption. > > It is easy to pass the array length, sizeof(...), and this can prevent API to > walk through beyond the pattern array. > And having the END withing the array can be verified in API level before passing > the data to the drivers, so driver interface and code can stay intact. Encoding 'END' within the array can only be enforced as an application semantic. The size of the array is a program / system semantic. They cannot be used interchangeably, and we certainly shouldn't omit the system semantic. Notice how we're fixing a case that was directly because of a programmer doing "the wrong thing" and an API that cannot protect against it in any fashion. That's in spite of some of your very first comments: because it's actually safer It isn't. People and programmers make mistakes. It's easier and more efficient to calculate the size of an array (ARRAY_SIZE() is a fairly well known macro) and pass it around. It's worse to _recalculate_ the size of an array each time (exponential execution) and have to constantly walk elements from the head. I didn't see the discussions on the flow API but I would have been really critical of passing flat arrays without a corresponding length. >> >> - [tons of other good reasons here] As Ferruh notes, there are *billions* of examples of C strings being a problem, and they are conceptually no different (a flat array with an embedded end marker). I think there might be 'reasons,' but I would hesitate to know any of them as 'good'. >> See? >>