Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp347806rwo; Tue, 1 Aug 2023 18:38:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlGjYYlegeE/G14Y87+jdnCHPSBlk+48P4tzZ0CT1JcVaKbUyf6y2MBWUz/3Ob/2tR6lNJGF X-Received: by 2002:a2e:a317:0:b0:2b9:3274:dbef with SMTP id l23-20020a2ea317000000b002b93274dbefmr3235910lje.45.1690940286156; Tue, 01 Aug 2023 18:38:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690940286; cv=none; d=google.com; s=arc-20160816; b=b+YzkmxxiYN4mVGI8wr4bt0WdILrL/o0f/sVzuBHHQlpmQ4Ty/AQrHIyIMnHUsfPAY 5/Ft4572Zb5tFxKUA38V2gh+jW86Whek6DeH1038E07Qz3ZE2nL005Ociijw1LtCl4uN eIEFavGFwBceavuQup/BiLy8YHt4lUslJUK234uzbBRi8r0zqJUxPCT7ZjQMDwyjDuZd VtIMpra8nDes4xP2STcniHrs6ZvKg3yvXcjs3MxXJyLoEU9GUNYRKwvQN79hxmohZXCb 8wfo98HY4NmEzKsGm3zUo/xHdAb+rvdgsgSZS+3w/kUOi1xtLOpJfQnEhc4sX6Pjea4y RKLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=MIHsj8XoFwDRolbPTByFLPNXyk7/+zhE5+wWIRLN6Lo=; fh=1JcSb2u7LMhaFiK/8zk1bPsYsm+kY9qcyz/Jo0jfyzk=; b=GxbGs5W+c1FsfUrYsgzDwU3kNT2T818Nof1/+0ba1t5tUnxfjcjMQnCyZ0Ap7IqYa8 323CWZxXJVX4qEq0Gi6jjqXmpRHOqoHJZvMQ62OB9kuQhyfiGVDx5ndFpjyVL9V+xrUx K4veUYBnHvn+vPy2FVF6g5fyxWxc42JXJuu9QLxgFbelWv2Hbx0lQGhGD7/SXFHFusS/ QFx7P02U8iEfaxIXYa6gF6XKGOgHhqGwsThgrNEzKCza58WvE+FyC9cjzAqPfPEn4edv rPu3cIwZN9ddqviH8EbInocd2NNxOBfVUEC992TG/r9w03qhK6asrXSAQxVpiSKm//fq 4ldA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=H8Pz5e5c; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r8-20020a170906c28800b00992f309cfe9si2950171ejz.598.2023.08.01.18.37.48; Tue, 01 Aug 2023 18:38:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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; dkim=pass header.i=@google.com header.s=20221208 header.b=H8Pz5e5c; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231404AbjHBBXU (ORCPT + 58 others); Tue, 1 Aug 2023 21:23:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231378AbjHBBXS (ORCPT ); Tue, 1 Aug 2023 21:23:18 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A9F32704 for ; Tue, 1 Aug 2023 18:23:16 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d1c693a29a0so7119351276.1 for ; Tue, 01 Aug 2023 18:23:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690939395; x=1691544195; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=MIHsj8XoFwDRolbPTByFLPNXyk7/+zhE5+wWIRLN6Lo=; b=H8Pz5e5cFzI5oJDwICKHGMhU3aoVAHffL5w/OGlv2mumGY89AiC3+vmNrVqUq3XE5c L415CZHlkHw7U28EfSPVE0GU5nr5YQUHuk6BfAzGOqb1Qpt3wLiBmHLFJSF6eVsCLUGZ yGGIsanfQZ7oOO5/ZhxjJ1C5VzOjwZYQ1K2h4hg81Sh5b5xThd+JkjqBd5/NegQXnhDj Q5kwiptlnJIB4VTHnUdUj3jWvT2ADKLlOeIRKqLB2VGFoXRNj/63Lm/wQXBY8jOE6FSC psZdL9fdN9/RJGn1NyQgBfYcc2N/Ii50oEiZEDzyMFiTe30gDNPemGNUX2YKFmjawmS2 wV0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690939395; x=1691544195; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=MIHsj8XoFwDRolbPTByFLPNXyk7/+zhE5+wWIRLN6Lo=; b=BDeNW9AkZ+hd7dDGo2l+xhDAl/HOF4JDt8cKLF+BpXE8KVuXTZnnNGhEdb65XUuwv5 /ctwaPRxOdZunWLvAOMgeNrkPv/6RumdMkR5/QUag/wwUdMoutL1FLqM5HmmRM3BnAHN WaSo48JyjMn4ejwTZXNJQSnqXsIr6kTe2k/7lsmKVKrr0NVnJYLPk/nkXFcAzajVY4HL RmB1R1JLa+UGXVftyJcsuq9oCBYeEUVmGPM7M0Jn1zKjnERxsBFVhB178tWhQzpjbDxz KpSipGgtT30hWxG7je2lwbq9sSSz59azJnbCzVhri0b/oM04jJChstWi/itii/6MW0ed hI0A== X-Gm-Message-State: ABy/qLaRoOhqk96GSaBIPzkHjV5IodBglpphWbf03iABj4hNT3d/Pqgv b/5yxhDfg73ZSrB0m7IAf0QKIYdNPnotDK3DYw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:69c7:0:b0:d07:f1ed:521a with SMTP id e190-20020a2569c7000000b00d07f1ed521amr92177ybc.4.1690939395731; Tue, 01 Aug 2023 18:23:15 -0700 (PDT) Date: Wed, 02 Aug 2023 01:23:06 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAPmvyWQC/42NywqDMBBFf0Wy7pQkxvhY9T+KizSOOtAaSYpax H9vFArdFLo8M/fcu7KAnjCwKlmZx4kCuSGCPCXM9mboEKiJzCSXKS+4gJlaAhpnuXAOHltjn85 Da3SDN211joZFd4wfWo7eax25pxBjr2NmEvv10yh/NE4CBKRZZrXIC1WK8tI5193xbN1jX/hH1 1zlOiuV4I361utt294UggXs+gAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1690939394; l=3748; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=g2L2WspPFLuzcaRk8qw4bGi3vzHIuHbW4yJAfdaLlnE=; b=YpPx3Ks0t64Zm8TmW6fpMsm4qnMsOvKhw3BlkoNW6xRuXjFDrgFrSv9CHD7qQ+tzcr9huNHcv GGaE44SBO6gAfGWrwh59cbIOX0pcCGhrZpxCqWTOho9JYDlX3POIRpy X-Mailer: b4 0.12.3 Message-ID: <20230802-wifi-ipw2x00-refactor-v2-1-d33f765e9cd5@google.com> Subject: [PATCH v2] wifi: ipw2x00: refactor to use kstrtoul From: Justin Stitt To: Stanislav Yakovlev , Kalle Valo Cc: Kees Cook , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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-wireless@vger.kernel.org The current implementation seems to reinvent what `kstrtoul` already does in terms of functionality and error handling. Remove uses of `simple_strtoul()` in favor of `kstrtoul()`. There is the following note at `lib/vsprintf.c:simple_strtoull()` which further backs this change: | * This function has caveats. Please use kstrtoull (or kstrtoul) instead. And here, simple_str* are explicitly deprecated [3]. This patch also removes an instance of the deprecated `strncpy` which helps [2]. Link: https://lore.kernel.org/all/202308011602.3CC1C0244C@keescook/ [1] Link: https://github.com/KSPP/linux/issues/90 [2] Link: https://docs.kernel.org/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull [3] Cc: linux-hardening@vger.kernel.org Suggested-by: Kees Cook Signed-off-by: Justin Stitt --- Link: https://lore.kernel.org/all/20230801-drivers-net-wireless-intel-ipw2x00-v1-1-ffd185c91292@google.com/ --- Changes in v2: - Create unsigned long and pass reference to kstrtoul (thanks Kees) - Link to v1: https://lore.kernel.org/r/20230802-wifi-ipw2x00-refactor-v1-1-6047659410d4@google.com --- drivers/net/wireless/intel/ipw2x00/ipw2200.c | 39 +++++++++------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/drivers/net/wireless/intel/ipw2x00/ipw2200.c b/drivers/net/wireless/intel/ipw2x00/ipw2200.c index dfe0f74369e6..820100cac491 100644 --- a/drivers/net/wireless/intel/ipw2x00/ipw2200.c +++ b/drivers/net/wireless/intel/ipw2x00/ipw2200.c @@ -1176,23 +1176,20 @@ static ssize_t debug_level_show(struct device_driver *d, char *buf) static ssize_t debug_level_store(struct device_driver *d, const char *buf, size_t count) { - char *p = (char *)buf; - u32 val; + unsigned long val; - if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { - p++; - if (p[0] == 'x' || p[0] == 'X') - p++; - val = simple_strtoul(p, &p, 16); - } else - val = simple_strtoul(p, &p, 10); - if (p == buf) + int result = kstrtoul(buf, 0, &val); + + if (result == -EINVAL) printk(KERN_INFO DRV_NAME ": %s is not in hex or decimal form.\n", buf); + else if (result == -ERANGE) + printk(KERN_INFO DRV_NAME + ": %s has overflowed.\n", buf); else ipw_debug_level = val; - return strnlen(buf, count); + return count; } static DRIVER_ATTR_RW(debug_level); @@ -1461,25 +1458,13 @@ static ssize_t scan_age_store(struct device *d, struct device_attribute *attr, { struct ipw_priv *priv = dev_get_drvdata(d); struct net_device *dev = priv->net_dev; - char buffer[] = "00000000"; - unsigned long len = - (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; - unsigned long val; - char *p = buffer; IPW_DEBUG_INFO("enter\n"); - strncpy(buffer, buf, len); - buffer[len] = 0; + unsigned long val; + int result = kstrtoul(buf, 0, &val); - if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { - p++; - if (p[0] == 'x' || p[0] == 'X') - p++; - val = simple_strtoul(p, &p, 16); - } else - val = simple_strtoul(p, &p, 10); - if (p == buffer) { + if (result == -EINVAL || result == -ERANGE) { IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); } else { priv->ieee->scan_age = val; @@ -1487,7 +1472,7 @@ static ssize_t scan_age_store(struct device *d, struct device_attribute *attr, } IPW_DEBUG_INFO("exit\n"); - return len; + return count; } static DEVICE_ATTR_RW(scan_age); --- base-commit: 5d0c230f1de8c7515b6567d9afba1f196fb4e2f4 change-id: 20230801-wifi-ipw2x00-refactor-fa6deb6c67ea Best regards, -- Justin Stitt