Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5739216rwl; Thu, 29 Dec 2022 02:03:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXvMw9VAxacAR9DThp4m9EL1iQQ/mbmEp+M/adQrigD5QejzfxjAXA37R2g6bfPcr0cN+pqy X-Received: by 2002:a05:6402:48c:b0:483:d49f:e26c with SMTP id k12-20020a056402048c00b00483d49fe26cmr14004524edv.15.1672308222852; Thu, 29 Dec 2022 02:03:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672308222; cv=none; d=google.com; s=arc-20160816; b=S3NYkPrtlMn07pMl2RftXYsBkrX70O2/PlL9rxgLnMttPWVP7vn3E1kuxj7fuAT2f4 72FU9aaRIoR5x5ex7PiUW1AR96KhEzwZ2aKNjx6AQ6HO1pVeRGFV12Pb2iNrCtRmOIlt rD5Ff2ZK2b2ctNcVl+IUt2RNWPZmODDczik3e5gXItj9BTJLcCRQlLt6HVAGz73hKHYs 67vgkLr8nYb78ryJ2DjsnfyAzLqZ/0vu4vHfWrsoVXkSO1+FmzSgoYYKBMzTpMPRFgRv hQIvD3cb5Sx9egJuY1APavUV4vpKFXAB8aRuBCQneVkLts6F329SRk6lnV86paNKWeHG D+cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sGQu9zaoGiTvvokNF12XdMZeXrMDq+udW21w5TfdmPU=; b=b2GTaDkunR3XB6HSkji8BXZiz3Frd6kSVElXikcaW7hErqkNgcjapcIAgNM1N4sJS0 NVoTKKEje/v4yjXyqI/EgjEjQ3EvUxfs0uX/j0lTT+vp79txdMcygfkH0Ger1tIKlwWG Ih4mBD6wJ5+A4NIU0exhqz42QthM7qEmo87+9A/Fi64HtKWwZYTo9LSlBZVcE9CJskQB KPq/58dFrUM4KE3HUKXblstTIqnj3Uo+zQR5uz6wDnkZyMWTuFZ5+0qrwKQMw/+yh5pV Z2vIfayufsi3JnPX3nUD9qwfd3xtv9rflAPbGJshpUJfiiSWV1GT7tltE1BYmh5acTjL +iXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Sr0cbGK6; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w21-20020a05640234d500b0045c31d9643bsi17689511edc.2.2022.12.29.02.03.13; Thu, 29 Dec 2022 02:03:42 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Sr0cbGK6; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231229AbiL2Jvl (ORCPT + 62 others); Thu, 29 Dec 2022 04:51:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbiL2JtX (ORCPT ); Thu, 29 Dec 2022 04:49:23 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B2B5BD8 for ; Thu, 29 Dec 2022 01:49:09 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id z10so16927364wrh.10 for ; Thu, 29 Dec 2022 01:49:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=sGQu9zaoGiTvvokNF12XdMZeXrMDq+udW21w5TfdmPU=; b=Sr0cbGK6iyGpJRqPGXFi/1Gt4IVqCB8HIYvN5Nc26ZnQ878k1xBdd7X6yHDuA1RGXD 4H45gVTxKCTQJz83XPxYSvGfzso0ZvGheZeN0T9/zXT2A/pZkDK68kwtYLwyW5uhC4tE 6YrTyURGoQ+aLNwOjNLiYIoB8hLjANRTOelFyuAeynbH3EOK9Pto2gqxkH09mOshh8HV Z1Ug0r86MWCZ9eJa/yizzA1VkvXSKg2a5bgaWAezlyAof21yVE2YUtvcj97Xt922x8aG i1Bh65DWfRspifsGK5MTEOGwF2M5TmdAhlq+v7J5iigTLA6geNghfXvtcvGs7CEuz2Rz Kgcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=sGQu9zaoGiTvvokNF12XdMZeXrMDq+udW21w5TfdmPU=; b=aStbIocXtiftc1BynBcYApHd2CPJTiLOdQ/dXDDwH78/LfquQnXwt43dnnVn9atoJc EYf8TmpO2a83Z/rzV0u9rliaj3sroU1VOwMD8ajQzI19gTpTUFRV2I0h5FcXhlegTKRe j+usFGjbCQQPY6fqKe2AecV10g/Oa8OQFMNoFj1Kr/KvI0vNZPAKhrqnFqwjahFC1+18 ZWVEHztc4/wY3BBj3PCbMLHP4CMXLuna7Bly4EdLiQocNi2Qi9Q60RbEVqb0gZvz67Fs wjnPNUEr1Tob2gwLASy8fKf055Www0Afg5XrZ2fj6V8G8ywouUA7Ieg/CJR6w9evOJ1f aQsg== X-Gm-Message-State: AFqh2krHkOgLuXhNkvJ+5hALV4DrZwsIQZruyx3Dfy8SfwLqxWKoMlyN 6NF7tSictR4bFCC1NkUh4Ak= X-Received: by 2002:a5d:4902:0:b0:281:cdb2:f351 with SMTP id x2-20020a5d4902000000b00281cdb2f351mr622047wrq.67.1672307347529; Thu, 29 Dec 2022 01:49:07 -0800 (PST) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b0027e5501f7f5sm9777775wru.53.2022.12.29.01.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 01:49:06 -0800 (PST) Date: Thu, 29 Dec 2022 12:49:04 +0300 From: Dan Carpenter To: yang.yang29@zte.com.cn Cc: gustavoars@kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, xu.panda@zte.com.cn Subject: Re: [PATCH linux-next] staging: ks7010: use strscpy() to instead of strncpy() Message-ID: References: <202212261903245548969@zte.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 On Thu, Dec 29, 2022 at 12:45:10PM +0300, Dan Carpenter wrote: > On Mon, Dec 26, 2022 at 07:03:24PM +0800, yang.yang29@zte.com.cn wrote: > > From: Xu Panda > > > > The implementation of strscpy() is more robust and safer. > > That's now the recommended way to copy NUL-terminated strings. > > > > Signed-off-by: Xu Panda > > Signed-off-by: Yang Yang > > --- > > drivers/staging/ks7010/ks_wlan_net.c | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > diff --git a/drivers/staging/ks7010/ks_wlan_net.c b/drivers/staging/ks7010/ks_wlan_net.c > > index 044c807ca022..e03c87f0bfe7 100644 > > --- a/drivers/staging/ks7010/ks_wlan_net.c > > +++ b/drivers/staging/ks7010/ks_wlan_net.c > > @@ -382,8 +382,7 @@ static int ks_wlan_get_nick(struct net_device *dev, > > return -EPERM; > > > > /* for SLEEP MODE */ > > - strncpy(extra, priv->nick, 16); > > - extra[16] = '\0'; > > + strscpy(extra, priv->nick, 17); > > I think this code is a buffer overflow. This is an implementation of > SIOCGIWNICKN. Huh... Maybe I'm wrong. I looked at a couple other implementations of SIOCGIWNICKN and they all seem to assume a 17 character buffer... Let me look deeper. I guess for now assume I am wrong. regards, dan carpenter