Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1080035pxb; Fri, 26 Feb 2021 01:54:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDHTMaWXEM1WptTHnyr2r6nBtEUmd09L/6B7RnWQc2Xh5F9L1kAB9sY51o5q8lTFPCOxwN X-Received: by 2002:a17:906:398c:: with SMTP id h12mr2414648eje.469.1614333262927; Fri, 26 Feb 2021 01:54:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614333262; cv=none; d=google.com; s=arc-20160816; b=wGZmWOfTf2hSi5ae0uZOrAXIgAxa/2Cantd1IYbYFXoiouiuXGkEIDZG2Qqh/C6XEm bcMA9RdlN5x80oSybyBGZFvdVxPs45+L4NR3pPy7Z92krs39ZriCkxkuG1dNRnLmr/Zm bn8UTSKzMPVOmBlHsOdhso0ciqrHdAi+7y4qtU2+agmjGthxDa6KjGN91nOJEYE8IAAk Vkfj1bsEx3M8+sNUOphQWBywMRhSPWOSXIqwI0N3Sd9USq8uqIx36jDLVPDg81aBoTCv e2CoBzGsRUi3CURgLg4DZ7aBIlDooJjf8akHzwXiwPoar9SdDCDMRWYp2BWYHMI00kw3 Fmyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=Qz7iF8KIepOE4aCxzuQPw/BTEyuyc4LjaMrR27h9584=; b=c/pLgE8CRkAoMEPNQmwKWvEYk84IRD/BWo6Fn+H7eIzXlql6fu7yJjN24qrkjjsbCh ySC5MiQ6HqjTgG3LcGaksH3tBFTZbNMYbIQGC24xfzK7Ib3PkZVbXUlQQZCPdwTlCe3o xaUv1Vj2PibuhxZv3Kp14MxulA9jYJ2daV35yJwZ5hZPg3UHTppDdLbTLnDcr5w9soES AnelcJMslUZExvdj1RrJvQYRynBnAAVzPVopqqjs2S5waQj9Lcf0xrXJCCkI0E1+o/kC f/Z2vtkb5LNl5xJaJ32ygKQdofS5FNP6XISO6F55sVi9QKSiIs663c/DBjuQKXW8IUS3 3Y9g== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si5601576ejo.415.2021.02.26.01.54.00; Fri, 26 Feb 2021 01:54:22 -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; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230430AbhBZJuK (ORCPT + 99 others); Fri, 26 Feb 2021 04:50:10 -0500 Received: from mail-ej1-f47.google.com ([209.85.218.47]:42775 "EHLO mail-ej1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230413AbhBZJtq (ORCPT ); Fri, 26 Feb 2021 04:49:46 -0500 Received: by mail-ej1-f47.google.com with SMTP id a22so13738461ejv.9 for ; Fri, 26 Feb 2021 01:49:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Qz7iF8KIepOE4aCxzuQPw/BTEyuyc4LjaMrR27h9584=; b=sn0jUN5rgOydijiWmV3xW/uL07ZhnJWtQ9rTgtnDinXOyJX8nyFTIZrWyBM8FOIeFE rNG1eGq86is9NMgqgwZeCKlY/UqSvTNnN1GodI6ZwlU3O9CZ8s7dFL+UHniqzI/hyHUP 397AKofvy1aeh6wcmolDFmIe5B+ZSWmcJ0fZ/EK/uGnVDYC2RiyB87ofgZzulhMjWnu1 tWJSE0+ywPJHIj3qO4W3ZvEd5DHgN5glI2gji32zSQPflQUU0pgjjxyak5n+2e8ougwB rwrbqb42h4M7BQYd3pfvPXCEZRsAkre//p865XaVFKboxzTPOwc/9kEHMXGX2GUSqUJz R6Rg== X-Gm-Message-State: AOAM531zzURWaQEU6aR+1LAUXgTDUv98asVYJAMKXCZHSNRG7daI2HtV qc2NL+UF/2Dk9EN7MZqGMorNHLzNWS1VSA== X-Received: by 2002:a17:906:1b0e:: with SMTP id o14mr2419608ejg.541.1614332943754; Fri, 26 Feb 2021 01:49:03 -0800 (PST) Received: from [192.168.1.49] (185-219-167-24-static.vivo.cz. [185.219.167.24]) by smtp.gmail.com with ESMTPSA id ke18sm2145756ejc.117.2021.02.26.01.49.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Feb 2021 01:49:03 -0800 (PST) Subject: Re: [PATCH 17/20] vt: Manual replacement of the deprecated strlcpy() with return values To: Romain Perier , Kees Cook , kernel-hardening@lists.openwall.com, Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org References: <20210222151231.22572-1-romain.perier@gmail.com> <20210222151231.22572-18-romain.perier@gmail.com> From: Jiri Slaby Message-ID: Date: Fri, 26 Feb 2021 10:49:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <20210222151231.22572-18-romain.perier@gmail.com> Content-Type: text/plain; charset=iso-8859-2; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22. 02. 21, 16:12, Romain Perier wrote: > The strlcpy() reads the entire source buffer first, it is dangerous if > the source buffer lenght is unbounded or possibility non NULL-terminated. "length" and it's NUL, not NULL in this case. > It can lead to linear read overflows, crashes, etc... > > As recommended in the deprecated interfaces [1], it should be replaced > by strscpy. > > This commit replaces all calls to strlcpy that handle the return values s/that/which/ ? "handles" "value" > by the corresponding strscpy calls with new handling of the return > values (as it is quite different between the two functions). Sorry, I have hard times understand the whole sentence. Could you rephrase a bit? > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy > > Signed-off-by: Romain Perier > --- > drivers/tty/vt/keyboard.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c > index 77638629c562..5e20c6c307e0 100644 > --- a/drivers/tty/vt/keyboard.c > +++ b/drivers/tty/vt/keyboard.c > @@ -2067,9 +2067,12 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm) > return -ENOMEM; > > spin_lock_irqsave(&func_buf_lock, flags); > - len = strlcpy(kbs, func_table[kb_func] ? : "", len); > + len = strscpy(kbs, func_table[kb_func] ? : "", len); func_table[kb_func] is NUL-terminated and kbs is of length len anyway, so this is only cosmetical. > spin_unlock_irqrestore(&func_buf_lock, flags); > > + if (len == -E2BIG) > + return -E2BIG; > + This can never happen, right? > ret = copy_to_user(user_kdgkb->kb_string, kbs, len + 1) ? > -EFAULT : 0; > > thanks, -- js