Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4912632pxb; Sun, 7 Nov 2021 01:02:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/Ugp0JAtxlOrxKmA8i9n3gUrcQon2SXRjHD5cmqFiNcl2FAb0DWfh5MTCPBQEDt0/hqzd X-Received: by 2002:a05:6e02:156a:: with SMTP id k10mr27498724ilu.200.1636275737764; Sun, 07 Nov 2021 01:02:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636275737; cv=none; d=google.com; s=arc-20160816; b=LuH3kUlEVtHCzdsMq80QtD5BTZGXMIWFxl1FvMIPgtpaP8c3G0UeLWXln6QguoF3Q7 tdQmSUWYv10mYtkwHGZQcgXEyCnNKyXZSF7+r5qHFuxzgs84OYlPprP5kHTarAmHGt1P 2pfk5c0WlOMtJn5wSDDN254dCvEZm3ZUtz7/7+aYY6UvOZi/FdImt9JYw+ZBUXYPQB6F P/RV0UgsE+rzyjoNsAWTlz/jNoeNXZS85HXeaTc8p5104muQbn+ZZruj4ShQIgsUlgzH prSsQr7r9JCGp55vKhXahuH7y+cEbtAMAkYkLr2anCZRrltluTBI0HjBIrOc6M5KPxb2 d2LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=ivr2Awm9A6W/30hhTq73ud4rsNlqaBVMqxR8KOFQptk=; b=Pf6Nw6FknZoNiTu2Afb/9dzY/pv2Xuu0zG8F68w6CF3SEqxOuejOFBe3j43mbC7FME Yr6lb4WbpOMejFW/tdgAnxDJOBOdc2pDS4hxnmhSrjezbnCbwy1SFaErstN61fiAo1VZ tGs3SgYaUcbJZ7Wg4wkU+2MKGQTyP5L0N0VU635EsdJqFk9/VVUZdVGy1o0d4rj0IChf bHGyw3xAxHESVUmr7dAJSzwj+50Xgp5//CZqduShVvuIl8R9fwSXES2qug/W2/8xxuUD 4HsIH/r79lw6vyguIDh5cWG/G19R7Hoj/iHl4g1BFO5qlXp+91bOX2lO1egTI2jtOmSy vQsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AKtRUSaj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q2si27354991jat.117.2021.11.07.01.02.05; Sun, 07 Nov 2021 01:02:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@gmail.com header.s=20210112 header.b=AKtRUSaj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S235055AbhKFUgq (ORCPT + 99 others); Sat, 6 Nov 2021 16:36:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbhKFUgp (ORCPT ); Sat, 6 Nov 2021 16:36:45 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EE65C061570; Sat, 6 Nov 2021 13:34:04 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id v15so14075919ljc.0; Sat, 06 Nov 2021 13:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=ivr2Awm9A6W/30hhTq73ud4rsNlqaBVMqxR8KOFQptk=; b=AKtRUSajJsvlDyun9EJrnS9kuS+3JXDGuUXdpPiWdMu8EyHVghqDAhCIKvfd51b9cV RwgAEMPDX9wBScMVLCEvlXaa+mXvkAIDyl5x1/DH0K48E7rTDieDAb5BS+IcrHVY7VFZ uwWRfYmxRamBiS1z/MkR1nl19jU1ezCllWgVANSoqZcgRDc1Vrts6v225rpsdmRDwM8A tRlF4tvjdzXFQliG7jEAA5+LOS/uOtJ7HBoVgoslk+eTi/LdAjF2UVO3ktOoiq402ZL1 OHc0cEuECX5EkWRACPXgejpcF+RX/hgoUKL7Vcq9lZQBhN5n1hd+CeqQrj0ca4OQXgRD zsng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=ivr2Awm9A6W/30hhTq73ud4rsNlqaBVMqxR8KOFQptk=; b=EfNxiReCt+qAa83Gszer2V9CzcgrdQzxdPfYn6KMl1B8/S9i4bsCtieF1rUzfNaffG Fh9aeyrDl86rqAzmlRJJ0DRhh40qoyEx4RZkkc+n9SYWii74104vjUoUbfPMCesWZgj9 cZSIi8afgtlSuw8Bf1vLm76dtH1t+vtN81V+ADIRtUzVTyrShsg3/qjfZpdMoVdwgLpv nQc9q1+jI3nHKIANWNyHK/22rSBZKx1DGSrimbyeOMtxTuQUEJCcncPIVRhGnOK2Yurr ojrAkXgL0HUBgsM/4Numd9cjYsA5bMQJVSwf0UMckBIfvxRqz3vMnhGPqBiLe3j2hjCw mThA== X-Gm-Message-State: AOAM532USi4UvX2Rh8JDb13OQ2/gs5mp5pnLuCOA041M21VDQma/Wb/x 9O9NlyPHSZN1botcuYrq7qI= X-Received: by 2002:a2e:7c0c:: with SMTP id x12mr15443100ljc.210.1636230842507; Sat, 06 Nov 2021 13:34:02 -0700 (PDT) Received: from [192.168.1.11] ([217.117.245.207]) by smtp.gmail.com with ESMTPSA id y1sm1248023lfd.204.2021.11.06.13.34.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Nov 2021 13:34:02 -0700 (PDT) Message-ID: <9717b429-597f-7778-c880-94361bcdee7f@gmail.com> Date: Sat, 6 Nov 2021 23:34:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH] tty: vt: keyboard: do not copy an extra-byte in copy_to_user Content-Language: en-US To: Ajay Garg Cc: Andy Shevchenko , Greg KH , jirislaby@kernel.org, kernel@esmil.dk, David Laight , "linux-serial@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <20211106092041.43745-1-ajaygargnsit@gmail.com> <9eafae1f-d9f0-298d-cf20-212865d0becc@gmail.com> <868025b485b94480ad17d0ec971b3ee9@AcuMS.aculab.com> <6b58a3e1-f2ea-cc4c-03b2-06334b559373@gmail.com> From: Pavel Skripkin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/6/21 23:30, Ajay Garg wrote: >> > 2. >> > == Calculate the actual length of kbs, add 1, and then copy those many >> > bytes to user-buffer == >> > >> > ret = copy_to_user(user_kdgkb->kb_string, kbs, len + 1) ? >> > -EFAULT : 0; >> > => >> > ret = copy_to_user(user_kdgkb->kb_string, kbs, strlen(kbs) + 1) ? >> > -EFAULT : 0; >> > >> >> But isn't strlen(kbs) is guaranteed to be equal to strlcpy() return >> value in this case? As I said in previous emails, >> strlen(func_table[kb_func]) < sizeof(user_kdgkb->kb_string) by design of >> this function. > > That's the whole point of the discussion :) > > The method "vt_do_kdgkb_ioctl" does not manage "func_table[kb_func]". > Thus, the method does not know whether or not > strlen(func_table[kb_func]) < sizeof(user_kdgkb->kb_string). > It manages. The code under `case KDSKBSENT:` sets func_table[] entries via vt_kdskbsent(). kbs = strndup_user(..., sizeof(user_kdgkb->kb_string)); is used to allocate buffer for the func_table[] entry. That's my main point :) With regards, Pavel Skripkin