From patchwork Wed Apr 21 23:43:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 425710 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4445CC433ED for ; Wed, 21 Apr 2021 23:43:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C68361427 for ; Wed, 21 Apr 2021 23:43:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343753AbhDUXnw (ORCPT ); Wed, 21 Apr 2021 19:43:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:38932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237964AbhDUXnu (ORCPT ); Wed, 21 Apr 2021 19:43:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 63266613DC; Wed, 21 Apr 2021 23:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619048597; bh=RBahKrZRpdTopHgPiuzI27MUkFSEAGAZ67SmGWh+3DA=; h=Date:From:To:Cc:Subject:From; b=HawRR0EyA/J/BBKRnMqHS/rwp9157ZqRy672M3zIdn6osTREHRUTyUsOztuIeNBwv 18dVY+LiqGuiI6AqZST9T6JOZ7QQu/uhWVN0fsYdgJO2pWLVcDloFfyxSzEBJrlYyZ jg8IWKZAbPuzuRKpPOlw3fjom97UiZcNZgbg88dvWMSt7qlwJGgiaPUCQjW6SeTcs3 s8yHOCIAwbIEGIwRWAoMKsfM0u4tIqC5+CS5tJyONUWL9MfSlcDsr2LMX4J7Kon4fx SCPzStU6jeK88OIqA9fZRKIV1RXlpoLO8bjDGVReUYM5FhP0X7eo6oJbvili+iYrIZ Ue5CLedEeWV5Q== Date: Wed, 21 Apr 2021 18:43:37 -0500 From: "Gustavo A. R. Silva" To: Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org, Kees Cook Subject: [PATCH][next] wireless: wext-spy: Fix out-of-bounds warning Message-ID: <20210421234337.GA127225@embeddedor> MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Fix the following out-of-bounds warning: net/wireless/wext-spy.c:178:2: warning: 'memcpy' offset [25, 28] from the object at 'threshold' is out of the bounds of referenced subobject 'low' with type 'struct iw_quality' at offset 20 [-Warray-bounds] The problem is that the original code is trying to copy data into a couple of struct members adjacent to each other in a single call to memcpy(). This causes a legitimate compiler warning because memcpy() overruns the length of &threshold.low and &spydata->spy_thr_low. As these are just a couple of members, fix this by copying each one of them in separate calls to memcpy(). Also, while there, use sizeof(threshold.qual) instead of sizeof(struct iw_quality)) in another call to memcpy() above. 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 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- net/wireless/wext-spy.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/wireless/wext-spy.c b/net/wireless/wext-spy.c index 33bef22e44e9..bb2de7c6bee4 100644 --- a/net/wireless/wext-spy.c +++ b/net/wireless/wext-spy.c @@ -120,8 +120,8 @@ int iw_handler_set_thrspy(struct net_device * dev, return -EOPNOTSUPP; /* Just do it */ - memcpy(&(spydata->spy_thr_low), &(threshold->low), - 2 * sizeof(struct iw_quality)); + memcpy(&spydata->spy_thr_low, &threshold->low, sizeof(threshold->low)); + memcpy(&spydata->spy_thr_high, &threshold->high, sizeof(threshold->high)); /* Clear flag */ memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under)); @@ -173,10 +173,10 @@ static void iw_send_thrspy_event(struct net_device * dev, memcpy(threshold.addr.sa_data, address, ETH_ALEN); threshold.addr.sa_family = ARPHRD_ETHER; /* Copy stats */ - memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality)); + memcpy(&threshold.qual, wstats, sizeof(threshold.qual)); /* Copy also thresholds */ - memcpy(&(threshold.low), &(spydata->spy_thr_low), - 2 * sizeof(struct iw_quality)); + memcpy(&threshold.low, &spydata->spy_thr_low, sizeof(threshold.low)); + memcpy(&threshold.high, &spydata->spy_thr_high, sizeof(threshold.high)); /* Send event to user space */ wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold);