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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Mon, 28 Sep 2020 18:48:54 -0700 (PDT)
From:   David Miller <davem@...emloft.net>
To:     gustavoars@...nel.org
Cc:     jhs@...atatu.com, xiyou.wangcong@...il.com, jiri@...nulli.us,
        kuba@...nel.org, netdev@...r.kernel.org,
        linux-kernel@...r.kernel.org, keescook@...omium.org
Subject: Re: [PATCH][next] net/sched: cls_u32: Replace one-element array
 with flexible-array member

From: "Gustavo A. R. Silva" <gustavoars@...nel.org>
Date: Mon, 28 Sep 2020 10:30:52 -0500

> There is a regular need in the kernel to provide a way to declare having
> a dynamically sized set of trailing elements in a structure. Kernel code
> should always use “flexible array members”[1] for these cases. The older
> style of one-element or zero-length arrays should no longer be used[2].
> 
> Refactor the code according to the use of a flexible-array member in
> struct tc_u_hnode and use the struct_size() helper to calculate the
> size for the allocations. Commit 5778d39d070b ("net_sched: fix struct
> tc_u_hnode layout in u32") makes it clear that the code is expected to
> dynamically allocate divisor + 1 entries for ->ht[] in tc_uhnode. Also,
> based on other observations, as the piece of code below:
> 
> 1232                 for (h = 0; h <= ht->divisor; h++) {
> 1233                         for (n = rtnl_dereference(ht->ht[h]);
> 1234                              n;
> 1235                              n = rtnl_dereference(n->next)) {
> 1236                                 if (tc_skip_hw(n->flags))
> 1237                                         continue;
> 1238
> 1239                                 err = u32_reoffload_knode(tp, n, add, cb,
> 1240                                                           cb_priv, extack);
> 1241                                 if (err)
> 1242                                         return err;
> 1243                         }
> 1244                 }
> 
> we can assume that, in general, the code is actually expecting to allocate
> that extra space for the one-element array in tc_uhnode, everytime it
> allocates memory for instances of tc_uhnode or tc_u_common structures.
> That's the reason for passing '1' as the last argument for struct_size()
> in the allocation for _root_ht_ and _tp_c_, and 'divisor + 1' in the
> allocation code for _ht_.
> 
> [1] https://en.wikipedia.org/wiki/Flexible_array_member
> [2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
> 
> Tested-by: kernel test robot <lkp@...el.com>
> Link: https://lore.kernel.org/lkml/5f7062af.z3T9tn9yIPv6h5Ny%25lkp@intel.com/
> Signed-off-by: Gustavo A. R. Silva <gustavoars@...nel.org>

Applied.

Powered by blists - more mailing lists