Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp330378pxb; Fri, 22 Apr 2022 01:37:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyo8oustQ/qIJiWmXKQafr68H31crouJSW0Hgd5Do++DsOnFmJDMy+WEXY83xLosQQk+8ol X-Received: by 2002:aa7:c5d4:0:b0:420:11ef:c1c9 with SMTP id h20-20020aa7c5d4000000b0042011efc1c9mr3666192eds.392.1650616660167; Fri, 22 Apr 2022 01:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650616660; cv=none; d=google.com; s=arc-20160816; b=aT0UrU2ROXGqVZ3t415MTcb4+piyFIrH77mnA/NjE0XHUaXKds57QbdW6drWrEzcgF z71bbLcVvFg9h9upoT31iXkI3FP2IURKEpQh+6kYjfm8Dmdd7DsVyfhs2Bz51/hVXfcL PSn4nJ8WwKbcBg9i51pk0/70rbz1MHRUCEz4ciihOgr0vmgtS2hM2Rs1ZKMJQRfYeK0B NAmKHNNWJ3/i5KWP3c2lC8GUvnII9f0ny7omWtXF+GJF1y5Sa3ZnduLZ/yS22ph15uAx A96fqLzyuEj6VKKnu/Vwoa8b00L6xxCFPWOYKdRIoakKanH664R/i8Hh8JgYIXRRAlJN LZxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=fbTuEKdlfU/QFThrBm1myl9iUf9DVfE7vOWb8tCk50E=; b=eRHLJ3tU43VHFeTiN5R9/lzT9I+GgUrXZLBWrvcMZWiOerXvdVDbQnB5SVUSfkeRH1 Mp6KopPZV85GkbR85YHbYKdqZ0de+14F1P4kRYZICzW6mDvg4oLeso0eYXIEsNAY6pO/ EKY1+X2kqz7Fwm3sQ6kX7cz4oICDAwTusPwY2lTe3K9y+h+kvc9ah6ZD4tZ+UVE0UpT5 jSTjX5uN/cfTH9Tfnl/bydUVhablJN5AcLuahcIbt15PsNlWSCVZNby3BmghvTbylt8p vk0MOzRbdrBTk/q3Nua8bNFnb8t3Y5KirDYTgrzAZPJRXVnKj0JYvrA8iY64KLZko7/N iy5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z10-20020a50eb4a000000b0041d864def44si5582116edp.125.2022.04.22.01.37.16; Fri, 22 Apr 2022 01:37:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386774AbiDUIZE (ORCPT + 99 others); Thu, 21 Apr 2022 04:25:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386758AbiDUIYx (ORCPT ); Thu, 21 Apr 2022 04:24:53 -0400 Received: from mail.meizu.com (edge05.meizu.com [157.122.146.251]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 822CC2124C for ; Thu, 21 Apr 2022 01:21:28 -0700 (PDT) Received: from IT-EXMB-1-125.meizu.com (172.16.1.125) by mz-mail12.meizu.com (172.16.1.108) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 21 Apr 2022 16:21:21 +0800 Received: from meizu.meizu.com (172.16.137.70) by IT-EXMB-1-125.meizu.com (172.16.1.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Thu, 21 Apr 2022 16:21:18 +0800 From: Haowen Bai To: CC: , , , , Subject: [PATCH V5] staging: rtl8192e: Fix signedness bug in rtllib_rx_assoc_resp() Date: Thu, 21 Apr 2022 16:21:17 +0800 Message-ID: <1650529277-7893-1-git-send-email-baihaowen@meizu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <202204211558.TapLZO4j-lkp@intel.com> References: <202204211558.TapLZO4j-lkp@intel.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.16.137.70] X-ClientProxiedBy: IT-EXMB-1-126.meizu.com (172.16.1.126) To IT-EXMB-1-125.meizu.com (172.16.1.125) X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The rtllib_rx_assoc_resp() function has a signedness bug because it's a declared as a u16 but it return -ENOMEM. When you look at it more closely it returns a mix of error codes including 0xcafe, -ENOMEM, and a->status which is WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG. This is a mess. Clean it up to just return standard kernel error codes. We can print out the a->status before returning a regular error code. The printks in the caller need to be adjusted as well. Signed-off-by: Haowen Bai --- V1->V2: reduce return random value; print its own error message. V2->V3: change commit message; change s16 -> int. V3->V4: 1. change message suggested by Dan Carpenter; 2. hold a->status in auth_parse() and return error code or 0 on success. 3. print le16_to_cpu(errcode) -> int %d. V4->V5: fix compile error. drivers/staging/rtl8192e/rtllib_softmac.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c index 82bf05eb1cbf..38ac733c3245 100644 --- a/drivers/staging/rtl8192e/rtllib_softmac.c +++ b/drivers/staging/rtl8192e/rtllib_softmac.c @@ -1764,7 +1764,7 @@ static void rtllib_softmac_check_all_nets(struct rtllib_device *ieee) spin_unlock_irqrestore(&ieee->lock, flags); } -static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb, +static inline int auth_parse(struct net_device *dev, struct sk_buff *skb, u8 **challenge, int *chlen) { struct rtllib_authentication *a; @@ -1773,7 +1773,7 @@ static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb, if (skb->len < (sizeof(struct rtllib_authentication) - sizeof(struct rtllib_info_element))) { netdev_dbg(dev, "invalid len in auth resp: %d\n", skb->len); - return 0xcafe; + return -EINVAL; } *challenge = NULL; a = (struct rtllib_authentication *) skb->data; @@ -1787,7 +1787,13 @@ static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb, return -ENOMEM; } } - return le16_to_cpu(a->status); + + if (a->status) { + netdev_dbg(dev, "auth_parse() failed\n"); + return -EINVAL; + } + + return 0; } static int auth_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest) @@ -2282,7 +2288,7 @@ rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb, static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb) { - u16 errcode; + int errcode; u8 *challenge; int chlen = 0; bool bSupportNmode = true, bHalfSupportNmode = false; @@ -2292,8 +2298,7 @@ static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb) if (errcode) { ieee->softmac_stats.rx_auth_rs_err++; netdev_info(ieee->dev, - "Authentication response status code 0x%x", - errcode); + "Authentication response status code %d", errcode); rtllib_associate_abort(ieee); return; } -- 2.7.4