Re: [netmod] CBOR YANG encoding of union & bits [draft-ietf-core-yang-cbor-12]

Carsten Bormann <cabo@tzi.org> Wed, 06 May 2020 15:52 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: netmod@ietfa.amsl.com
Delivered-To: netmod@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 44F603A083B; Wed, 6 May 2020 08:52:48 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.899
X-Spam-Level:
X-Spam-Status: No, score=-1.899 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UZcYy5NXJZH5; Wed, 6 May 2020 08:52:45 -0700 (PDT)
Received: from gabriel-vm-2.zfn.uni-bremen.de (gabriel-vm-2.zfn.uni-bremen.de [134.102.50.17]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 8F1CA3A084B; Wed, 6 May 2020 08:52:45 -0700 (PDT)
Received: from [172.16.42.112] (p548DCD70.dip0.t-ipconnect.de [84.141.205.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gabriel-vm-2.zfn.uni-bremen.de (Postfix) with ESMTPSA id 49HLhW5vhYzyst; Wed, 6 May 2020 17:52:43 +0200 (CEST)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <BY5PR11MB4355C26250C9CF46713C9956B5A40@BY5PR11MB4355.namprd11.prod.outlook.com>
Date: Wed, 06 May 2020 17:52:43 +0200
Cc: "core@ietf.org" <core@ietf.org>, "netmod@ietf.org" <netmod@ietf.org>, "draft-ietf-core-yang-cbor@ietf.org" <draft-ietf-core-yang-cbor@ietf.org>
X-Mao-Original-Outgoing-Id: 610473163.169731-0d1a5aae028e7031f9f6528a208f3dfb
Content-Transfer-Encoding: quoted-printable
Message-Id: <D66596CE-7F5C-4562-89A4-48FCE96D0E18@tzi.org>
References: <BY5PR11MB4355C26250C9CF46713C9956B5A40@BY5PR11MB4355.namprd11.prod.outlook.com>
To: "Rob Wilton (rwilton)" <rwilton=40cisco.com@dmarc.ietf.org>
X-Mailer: Apple Mail (2.3608.80.23.2.2)
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/JqiYK6rGf6MXFDidJPtWrDWIUDQ>
Subject: Re: [netmod] CBOR YANG encoding of union & bits [draft-ietf-core-yang-cbor-12]
X-BeenThere: netmod@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: NETMOD WG list <netmod.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/netmod>, <mailto:netmod-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/netmod/>
List-Post: <mailto:netmod@ietf.org>
List-Help: <mailto:netmod-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/netmod>, <mailto:netmod-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 06 May 2020 15:52:48 -0000

Hi Rob,

> 1) Regarding the encoding of the bits datatype:
> [draft-ietf-core-yang-cbor-12, section 6.7]
> 
> The CBOR YANG encoding of the bits datatype is defined as a byte string encoding of a bitfield.  However, my concern here is that YANG bit positions are allowed to be up 2^32-1.
> 
> E.g. the following, pathologically bad, bits definition would seem to have a very inefficient encoding in CBOR:
> 
>   typedef alarm-state {
>     type bits {
>       bit unknown {
>         position 4000000000;

My knee jerk reaction would be “don’t do that then” [1].

[1]: http://catb.org/jargon/html/D/Don-t-do-that-then-.html

>       }
>       bit under-repair;
>       bit critical;
>       bit major;
>       bit minor;
>       bit warning;
>       bit indeterminate;
>     }
>   }
> 
> 
> How much should we be concerned about this pathological case?  Would it be reasonable for implementations to reject bitfields larger than a small set size (e.g. perhaps 256 bits)?
> 
> Or, if it is supported by the language then is it reasonable that implementation SHOULD support it?  In which case I think that we might need a second encoding of bits that supports this pathological case.  Perhaps an array of 'set' bit positions, or alternatively the union string encoding of bits could be used.

This could reduce the attack vector by malicious YANG specification, but I think an arbitrary limit (such as the 256 mentioned above) should work, too.
(Except that arbitrary limits always come back to bite you, but that’s what we have software maintenance contracts for.)

> 2) Regarding the encoding of unions:
> 
> I was questioning whether the special encoding of bits type within a union was required in CBOR [draft-ietf-core-yang-cbor-12, section 6.7].  Am I right to presume that this is to ensure that the CBOR encoding of unions is always at least as specific as XML?  If so, this seems like a reasonable design choice.  

The semantics of Union types in YANG is closely married to the XML representation of YANG; if two branches of a union have a (non-empty) intersection in their XML encoding, this ambiguity is pretty much considered a feature.
So YANG-CBOR falls back to something that looks more like XML encoding (i.e., is less efficient) in unions.
The one nice thing is that a YANG spec writer can avoid the pathology by not using unions in this way; unfortunately, the fallback cannot rely on recognizing that the intersection is non-empty.

It occurs to me that this fallback could also be used for the above anomalies; we would need to agree on a threshold when that becomes active.

> But that leads on to these general YANG questions:
> 
> Should the value encoding of a YANG union type behave the same way regardless of whether the encoding is XML/JSON/CBOR?  

Of course it “should”, while retaining reasonableness for each of the encodings, but that ship seems to have sailed (at least for 1.0/1.1).

> Or is it reasonable for there to be differences in the case of conflicting values?  Perhaps this is already answered by RFC 7951 that can behave differently from the XML encoding of unions.
> 
> Longer term, should YANG be looking for a discriminated-union type?  Or perhaps it would be sufficient for tooling to flag up potentially ambiguous union definitions, particularly those that may be encoding dependent.

These are all good questions.
I don’t have an answer, except that the marriage of YANG to XML semantics probably should get a divorce at some point.

Grüße, Carsten