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>] [day] [month] [year] [list]
Date:   Thu, 10 Feb 2022 06:08:45 +0000
From:   cgel.zte@...il.com
To:     davem@...emloft.net
Cc:     kuba@...nel.org, netdev@...r.kernel.org,
        linux-kernel@...r.kernel.org,
        "Minghao Chi (CGEL ZTE)" <chi.minghao@....com.cn>,
        Zeal Robot <zealci@....com.cn>
Subject: [PATCH V2] net/802: use struct_size over open coded arithmetic

From: "Minghao Chi (CGEL ZTE)" <chi.minghao@....com.cn>

Replace zero-length array with flexible-array member and make use
of the struct_size() helper in kmalloc(). For example:

struct garp_attr {
    struct rb_node            node;
    enum garp_applicant_state    state;
    u8                type;
    u8                dlen;
    unsigned char            data[];
};

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

Reported-by: Zeal Robot <zealci@....com.cn>
Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@....com.cn>
---
 net/802/mrp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/802/mrp.c b/net/802/mrp.c
index 35e04cc5390c..880cb9ed9c4b 100644
--- a/net/802/mrp.c
+++ b/net/802/mrp.c
@@ -273,7 +273,7 @@ static struct mrp_attr *mrp_attr_create(struct mrp_applicant *app,
 			return attr;
 		}
 	}
-	attr = kmalloc(sizeof(*attr) + len, GFP_ATOMIC);
+	attr = kmalloc(struct_size(attr, data, len), GFP_ATOMIC);
 	if (!attr)
 		return attr;
 	attr->state = MRP_APPLICANT_VO;
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ