From patchwork Tue Jul 19 22:29:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12923153 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 137EB1115 for ; Tue, 19 Jul 2022 22:31:59 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id v21so13273234plo.0 for ; Tue, 19 Jul 2022 15:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FAOXs5sPYpAd3JYZJAak7nteBqKxRy/XZF3cYtGQDZ0=; b=hW+aNv7IJ3Dtkq+0Ez0SLKn4M0OHlAPuGRb9qxfFvYhkfh0l+Pwqfij754sWqDMppo vhIgg+QghxJzODAdnLchSPp7mP0EsJjCaMa2yd63lXY9gmYygW5HpElE+bkgEas69NxR iwzdd1XtXSzxPCuFGwQTs6JFB59j9Pynsh3kOTetMeH5zYgpqVQVYacHy5LyAcaQaPc1 0JZmbDiq6rIXSj7YbXsWDhXvOH2UNDtux8TgX13YV8VyZE1VNW9pIf2Cz161HgcqNTPj cLotb7Jm1wpm7axsJiqIruBKrLWPf52W4Z0FHc+pODv9eee/XWBV85sMA1wdv1X0UDbl 5O2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FAOXs5sPYpAd3JYZJAak7nteBqKxRy/XZF3cYtGQDZ0=; b=6CaCAPgoU1aWrNQxbViUAKqZaPICP63sOkC9D9D5YJyrDPDo7dqPGdZ+1U3A0kwhni 82DvFnRzgH7hCnoK/NTGy8g63PNevLFABEhJDGjwU67rJlW3DH3Thm48q3gX/DxkVF5C YOrtlLacvqBoQoTXFrsQ000PPzviUK9mpT1o4EHK++IcIeJYRlAHtsGKA/5NtwbbDoEQ JpfQ4yPaEPbpXoMEJ6aEx4xjs/RKdk48Kf2svRV0mF4kTLj2pRlQ5L33wNCCOc5QGbTL S5NL5TK+4Sgz8Wt8pZnGQ0HUAKaZqEo/jiJpy4kRUQlOWfwTDE+au05wcGuvXEgq3fIy 88mA== X-Gm-Message-State: AJIora+3TiPyFWal9fI9DuOE3vPFn+XM9CRkta70CXaIJUFFHO4Qle1Z 9dQ+8olWvTIRHGrZVfVhL7csPuC86OM= X-Google-Smtp-Source: AGRyM1uwqbjvUw2A2WZp8X66hrg8YFBT554mkA782pSFKXFsEf2x8Fa+HdIO90CTbq+jsh6mmXOXkQ== X-Received: by 2002:a17:90a:404f:b0:1f2:126b:ba29 with SMTP id k15-20020a17090a404f00b001f2126bba29mr1822777pjg.74.1658269919135; Tue, 19 Jul 2022 15:31:59 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id g3-20020a170902e38300b0015e8d4eb1c8sm12067154ple.18.2022.07.19.15.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 15:31:58 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 1/2] unit: memset band to zero after alloc Date: Tue, 19 Jul 2022 15:29:49 -0700 Message-Id: <20220719222950.540619-1-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In test-band the band object was allocated using l_malloc, but not memset to zero. This will cause problems if allocated pointers are included in struct band once band is freed. --- unit/test-band.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unit/test-band.c b/unit/test-band.c index 757db377..0dd9b67b 100644 --- a/unit/test-band.c +++ b/unit/test-band.c @@ -52,6 +52,8 @@ static struct band *new_band() /* band + 8 basic rates */ struct band *band = l_malloc(sizeof(struct band) + 8); + memset(band, 0, sizeof(struct band) + 8); + band->supported_rates_len = 8; band->supported_rates[0] = 12; band->supported_rates[1] = 18; From patchwork Tue Jul 19 22:29:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12923154 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60CB553A7 for ; Tue, 19 Jul 2022 22:32:00 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id w7so828223plp.5 for ; Tue, 19 Jul 2022 15:32:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wg0FqvAGdQmhWcx1Rh6Wtr2dDeDZXDZaJsqxMuBDV3g=; b=Ld23kgmVlkcgklKQ5YXxLOkpLtdfqmmWPgDYhfzxGTzE7Gxen/EXdJJ6vLI2eVm9jW 5lEIWx+2lwWCqqoAIRQdGGXS6EDuZXrj8asxsGi7beH0K7us6EVUeMPUnSxzGK5KG77a 6y9YDGE9ouNsGNTRppJVa+8QXuSRG3Bsg/DyPYJ1/q5SzfIC9kY3/T6sYh2e0DWLfl3F P8jb/nVi39XkgBYK6badu+1lwdkNEJ/rxNdY/UoVyqSnt4J37/jPyHd3fyQwLpNtZiLe eD9g4cMhf5vPcUx7xMbuM+CJcDMpNkwqpg2j2bzU/eM0XDcCJYsvkMdzvZSgQSu8EZkk 3SPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wg0FqvAGdQmhWcx1Rh6Wtr2dDeDZXDZaJsqxMuBDV3g=; b=oP3Xt0NgiuaIlYhuA/NVGas9O8AZtd7iimaZePMUUk6Vhv4uBHPNgdzDpS9xKJYRSU CZLuE5goSFAOlrtM7FPLoa4tx4/FUNQbSz5MVvqToclfllqnIQ6DwR5HGo8aNSbTHWV9 9ix0WTqUeBfh+WKCjOwwI+5QGAuCriWJXblzIJ7Uhiqtd2eQ2CGuu7ui8g7xsePSvCPm EHJVgRR0kQ/qv4A+d81EXvmswx1OIeg3+KUdxLVCSvF1FjXKoqa9OgXYtwqPY94nhpW2 QKHIjI4Ds9HHrNgH0crEJYMaZRWnY9+KCMDiMtRTAfjyH8mARseIgfjjz18u8pRNvBD6 f+pw== X-Gm-Message-State: AJIora+TLjHC3oA8HXKvGlSRIoQ4Ic/fk1RwC4fooMTBdIRezuCamMoW YtmsLpfk2S0vfy4HbJasIVX8eCNKFW8= X-Google-Smtp-Source: AGRyM1snjyeUwaqPcfYy1xWZ+JjPMUQtOww+0wUXTVsi70qqLMlzs+9riBmztdl434aMbMNCCLOLng== X-Received: by 2002:a17:90a:460e:b0:1f1:acb6:34 with SMTP id w14-20020a17090a460e00b001f1acb60034mr1761885pjg.167.1658269919641; Tue, 19 Jul 2022 15:31:59 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id g3-20020a170902e38300b0015e8d4eb1c8sm12067154ple.18.2022.07.19.15.31.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 15:31:59 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 2/2] wiphy: fix strange compiler bug with gcc 11.2 Date: Tue, 19 Jul 2022 15:29:50 -0700 Message-Id: <20220719222950.540619-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220719222950.540619-1-prestwoj@gmail.com> References: <20220719222950.540619-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There appears to be a compiler bug with gcc 11.2 which thinks the vht_mcs_set is a zero length array, and the memset of size 8 is out of bounds. This is only seen once an element is added to 'struct band'. In file included from /usr/include/string.h:519, from src/wiphy.c:34: In function ‘memset’, inlined from ‘band_new_from_message’ at src/wiphy.c:1300:2, inlined from ‘parse_supported_bands’ at src/wiphy.c:1423:11, inlined from ‘wiphy_parse_attributes’ at src/wiphy.c:1596:5, inlined from ‘wiphy_update_from_genl’ at src/wiphy.c:1773:2: /usr/include/bits/string_fortified.h:59:10: error: ‘__builtin_memset’ offset [0, 7] is out of the bounds [0, 0] [-Werror=array-bounds] 59 | return __builtin___memset_chk (__dest, __ch, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 60 | __glibc_objsize0 (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ --- src/wiphy.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wiphy.c b/src/wiphy.c index a52d0941..4dcfb8b3 100644 --- a/src/wiphy.c +++ b/src/wiphy.c @@ -1187,7 +1187,15 @@ static struct band *band_new_from_message(struct l_genl_attr *band) toalloc = sizeof(struct band) + count * sizeof(uint8_t); ret = l_malloc(toalloc); memset(ret, 0, toalloc); + +#if __GNUC__ == 11 && __GNUC_MINOR__ == 2 +_Pragma("GCC diagnostic push") +_Pragma("GCC diagnostic ignored \"-Warray-bounds\"") +#endif memset(ret->vht_mcs_set, 0xff, sizeof(ret->vht_mcs_set)); +#if __GNUC__ == 11 && __GNUC_MINOR__ == 2 +_Pragma("GCC diagnostic pop") +#endif return ret; }