Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp530041pxy; Thu, 22 Apr 2021 07:40:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysDM37NAKhwDDmZOJki45q6uj8jexcts91GaeEu0sn1TXkBcL0o8Zlfqw+T9n2ecpN7fPm X-Received: by 2002:a17:907:770d:: with SMTP id kw13mr3677177ejc.339.1619102408335; Thu, 22 Apr 2021 07:40:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619102408; cv=none; d=google.com; s=arc-20160816; b=l3ZwC2ZLI27qmUZRBbs2byeiL27WybbA7rOxOQ5XfyJveNCRow7NXNh9QW1CO8Xqvn N6yPfAtS/fNOQQfP5RbvWaX8QbC8WEVH75qHPiGYZ0e6aMZ/pjZOMUKoHuJeALIHkqgc 53rTkC5Uw1y/Nme8kPeuV8J+a9atAFXBl7XjjiFhO9dx3uFG/a8TgRWqIGC+/b4axo8b 8x0Uu8wQDFkeqabaPAU1aNf+fN/UWoqrtpKbQZOYJE2kcS7i4I5bCyYLWf2EoK+OQbdU M79CjcXMQTchoDqjlC9BdD5yIaHq0ftd7Bt4wEurzokRYGXtDHD+/dr8azed3S2UKtoV 3t6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:message-id:user-agent:cc:to:references :in-reply-to:from:subject:content-transfer-encoding:mime-version :dmarc-filter:sender:dkim-signature; bh=RMf3EFzLqxN1uAcl/snGb/NnTMeGSO6NhHpgmnX57QQ=; b=pbV8hkA/gExGDWe9k8ELzPUEMm4IlmzHWqbs7T+Jxe1NiTHVcWlDtIq8WJoaYK3ACw WRAuZ1WbApIR8DNr0kTRhr8D4/SQGNzGn4/JuQ6QxPA+Qwl1w7tVCjlZGuAnyGVscozJ XKxsIGeK8BfO182L+3wKJ/g9/9VjET5su13wrASP7bq9AUAD2EU8lXYN/+vJRxqHNTB8 seUkk7nvg3sOJkzY28STTeRKKAEszSWw3Y+D3N9B2M3stm7jjmm+xq2KaPpf26CGxnvl yewhnuMzogBVtcZqt6nUt3FU9Jw0+Bdx6PVhfdA6f15FL1/ZFLnb24uADURdycwUQewp R5KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=NYpTLVj1; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si2603163ejv.631.2021.04.22.07.39.44; Thu, 22 Apr 2021 07:40:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=NYpTLVj1; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236975AbhDVOkG (ORCPT + 99 others); Thu, 22 Apr 2021 10:40:06 -0400 Received: from so254-9.mailgun.net ([198.61.254.9]:19757 "EHLO so254-9.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236464AbhDVOkE (ORCPT ); Thu, 22 Apr 2021 10:40:04 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1619102369; h=Date: Message-Id: Cc: To: References: In-Reply-To: From: Subject: Content-Transfer-Encoding: MIME-Version: Content-Type: Sender; bh=RMf3EFzLqxN1uAcl/snGb/NnTMeGSO6NhHpgmnX57QQ=; b=NYpTLVj13p9HE70GBt/+qAZ0TEIU5xY0EZMDs6soaZFEm+GAHCrvorZ9R0PJYXwHWXxN1s7Z LqMuR83xhJbDdTAZW9EwCOGfaYrx9P9E9YWMoGs/0tkTfA+Yn/1FXic9fP9L0vxvQ3VbXsWb Nc6Po+lVhrlPRHU6pHFbi551Uus= X-Mailgun-Sending-Ip: 198.61.254.9 X-Mailgun-Sid: WyI3YTAwOSIsICJsaW51eC13aXJlbGVzc0B2Z2VyLmtlcm5lbC5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n06.prod.us-east-1.postgun.com with SMTP id 60818a8f2cbba8898039bc18 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Thu, 22 Apr 2021 14:39:11 GMT Sender: kvalo=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id DCAC0C433F1; Thu, 22 Apr 2021 14:39:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,BAYES_00, MISSING_DATE,MISSING_MID,SPF_FAIL autolearn=no autolearn_force=no version=3.4.0 Received: from potku.adurom.net (88-114-240-156.elisa-laajakaista.fi [88.114.240.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: kvalo) by smtp.codeaurora.org (Postfix) with ESMTPSA id DDE4FC433F1; Thu, 22 Apr 2021 14:39:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org DDE4FC433F1 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=kvalo@codeaurora.org Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [PATCH v3 1/2] wl3501_cs: Fix out-of-bounds warnings in wl3501_send_pkt From: Kalle Valo In-Reply-To: References: To: "Gustavo A. R. Silva" Cc: linux-kernel@vger.kernel.org, "David S. Miller" , Jakub Kicinski , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org, "Gustavo A. R. Silva" , Kees Cook User-Agent: pwcli/0.1.0-git (https://github.com/kvalo/pwcli/) Python/3.5.2 Message-Id: <20210422143910.DCAC0C433F1@smtp.codeaurora.org> Date: Thu, 22 Apr 2021 14:39:10 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org "Gustavo A. R. Silva" wrote: > Fix the following out-of-bounds warnings by enclosing structure members > daddr and saddr into new struct addr, in structures wl3501_md_req and > wl3501_md_ind: > > arch/x86/include/asm/string_32.h:182:25: warning: '__builtin_memcpy' offset [18, 23] from the object at 'sig' is out of the bounds of referenced subobject 'daddr' with type 'u8[6]' {aka 'unsigned char[6]'} at offset 11 [-Warray-bounds] > arch/x86/include/asm/string_32.h:182:25: warning: '__builtin_memcpy' offset [18, 23] from the object at 'sig' is out of the bounds of referenced subobject 'daddr' with type 'u8[6]' {aka 'unsigned char[6]'} at offset 11 [-Warray-bounds] > > Refactor the code, accordingly: > > $ pahole -C wl3501_md_req drivers/net/wireless/wl3501_cs.o > struct wl3501_md_req { > u16 next_blk; /* 0 2 */ > u8 sig_id; /* 2 1 */ > u8 routing; /* 3 1 */ > u16 data; /* 4 2 */ > u16 size; /* 6 2 */ > u8 pri; /* 8 1 */ > u8 service_class; /* 9 1 */ > struct { > u8 daddr[6]; /* 10 6 */ > u8 saddr[6]; /* 16 6 */ > } addr; /* 10 12 */ > > /* size: 22, cachelines: 1, members: 8 */ > /* last cacheline: 22 bytes */ > }; > > $ pahole -C wl3501_md_ind drivers/net/wireless/wl3501_cs.o > struct wl3501_md_ind { > u16 next_blk; /* 0 2 */ > u8 sig_id; /* 2 1 */ > u8 routing; /* 3 1 */ > u16 data; /* 4 2 */ > u16 size; /* 6 2 */ > u8 reception; /* 8 1 */ > u8 pri; /* 9 1 */ > u8 service_class; /* 10 1 */ > struct { > u8 daddr[6]; /* 11 6 */ > u8 saddr[6]; /* 17 6 */ > } addr; /* 11 12 */ > > /* size: 24, cachelines: 1, members: 9 */ > /* padding: 1 */ > /* last cacheline: 24 bytes */ > }; > > The problem is that the original code is trying to copy data into a > couple of arrays adjacent to each other in a single call to memcpy(). > Now that a new struct _addr_ enclosing those two adjacent arrays > is introduced, memcpy() doesn't overrun the length of &sig.daddr[0] > and &sig.daddr, because the address of the new struct object _addr_ > is used, instead. > > This helps with the ongoing efforts to globally enable -Warray-bounds > and get us closer to being able to tighten the FORTIFY_SOURCE routines > on memcpy(). > > Link: https://github.com/KSPP/linux/issues/109 > Reported-by: kernel test robot > Reviewed-by: Kees Cook > Signed-off-by: Gustavo A. R. Silva 2 patches applied to wireless-drivers-next.git, thanks. 820aa37638a2 wl3501_cs: Fix out-of-bounds warnings in wl3501_send_pkt bb43e5718d8f wl3501_cs: Fix out-of-bounds warnings in wl3501_mgmt_join -- https://patchwork.kernel.org/project/linux-wireless/patch/d260fe56aed7112bff2be5b4d152d03ad7b78e78.1618442265.git.gustavoars@kernel.org/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches