lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 12 Jun 2023 16:55:17 +0000
From: "Keller, Jacob E" <jacob.e.keller@...el.com>
To: Jakub Kicinski <kuba@...nel.org>, "davem@...emloft.net"
	<davem@...emloft.net>
CC: "netdev@...r.kernel.org" <netdev@...r.kernel.org>, "edumazet@...gle.com"
	<edumazet@...gle.com>, "pabeni@...hat.com" <pabeni@...hat.com>, "Kubalewski,
 Arkadiusz" <arkadiusz.kubalewski@...el.com>
Subject: RE: [PATCH net-next 1/2] tools: ynl-gen: correct enum policies



> -----Original Message-----
> From: Jakub Kicinski <kuba@...nel.org>
> Sent: Monday, June 12, 2023 8:59 AM
> To: davem@...emloft.net
> Cc: netdev@...r.kernel.org; edumazet@...gle.com; pabeni@...hat.com;
> Kubalewski, Arkadiusz <arkadiusz.kubalewski@...el.com>; Jakub Kicinski
> <kuba@...nel.org>
> Subject: [PATCH net-next 1/2] tools: ynl-gen: correct enum policies
> 
> Scalar range validation assumes enums start at 0.
> Teach it to properly calculate the value range.
> 
> Signed-off-by: Jakub Kicinski <kuba@...nel.org>
> ---

Reviewed-by: Jacob Keller <jacob.e.keller@...el.com>

>  tools/net/ynl/ynl-gen-c.py | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
> index 870f98d0e12c..54777d529f5e 100755
> --- a/tools/net/ynl/ynl-gen-c.py
> +++ b/tools/net/ynl/ynl-gen-c.py
> @@ -300,8 +300,10 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr,
> SpecOperation, SpecEnumSet, S
>              return f"NLA_POLICY_MIN({policy}, {self.checks['min']})"
>          elif 'enum' in self.attr:
>              enum = self.family.consts[self.attr['enum']]
> -            cnt = len(enum['entries'])
> -            return f"NLA_POLICY_MAX({policy}, {cnt - 1})"
> +            low, high = enum.value_range()
> +            if low == 0:
> +                return f"NLA_POLICY_MAX({policy}, {high})"
> +            return f"NLA_POLICY_RANGE({policy}, {low}, {high})"
>          return super()._attr_policy(policy)
> 
>      def _attr_typol(self):
> @@ -676,6 +678,15 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr,
> SpecOperation, SpecEnumSet, S
>      def new_entry(self, entry, prev_entry, value_start):
>          return EnumEntry(self, entry, prev_entry, value_start)
> 
> +    def value_range(self):
> +        low = min([x.value for x in self.entries.values()])
> +        high = max([x.value for x in self.entries.values()])
> +
> +        if high - low + 1 != len(self.entries):
> +            raise Exception("Can't get value range for a noncontiguous enum")
> +

Guessing we don't anticipate any non-contiguous enums so an exception here is fine

> +        return low, high
> +
> 
>  class AttrSet(SpecAttrSet):
>      def __init__(self, family, yaml):
> --
> 2.40.1
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ