Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp228971iol; Thu, 9 Jun 2022 02:42:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXruC2e56kjEdyqvvCrBWhSxpjTiK0LiHe6m0Io8UU5Jl1P+7dpWd5VE81dbxCmCad7lK4 X-Received: by 2002:a17:90b:4f45:b0:1e3:495a:2b51 with SMTP id pj5-20020a17090b4f4500b001e3495a2b51mr2574713pjb.3.1654767771975; Thu, 09 Jun 2022 02:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654767771; cv=none; d=google.com; s=arc-20160816; b=pgEaXfqauJ4EKdcbF5bwOr69CeP7bgMhnbjQW41JXAmHYJ7dHnAXetO7C2bAH9hZcj Z18s4oU3Ik6gADdUcIZlxkhjvW0vAPJKBSUasq/rJaWQH8jh0yLSXXpXTXusjn1L8Uvx sZFvBycCQTKLn5wZgqd2n+BPfLuaiiE/XvxxoU7GMdAj5HH4OKNrld8ay9tWB+qN69tV QYJZANr22zylj4znmKA2ykOpZwra6mYPNBjZNFheLwrSRAGr4xCir1lYhp+DQVwLEi/i nWTbMh1Qm0+NffEu2cXnyBFV0I3s4He8zs8gdWMf3NpwV/XeK49Qx5OBE3MI7qdM5S1k MUcA== 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:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id; bh=SXRFuRSOer0UTWqXklwZQzcqdPi/nxqTmlZiGWPV4ZU=; b=qXDjJPSUjfvohLtzj+MWpjo6NR0KSpG1NOzLM/AOJOLayPGyWSTWQT0nCQ1WmF/KF2 nsXcTKjz8iObZpvJn6OCqvYi/Z1tppvFk2pyzsN+2GotRNwH6ArztMDk8QVhaOoKv27L KyufBZJV2QDs53ftAhIJpW0yrJlesK24qmhJj0gvxueInsDyk6y6y4JWWEbD4n1Dgo4J wjSS8KKKu06QEyDuLG2DBo47i76d7788lx1Y+1ZxHbWAMBx6AY+7WcoMIPK6wOWjgmas W1lpjtpApQ5JuxEdXUGOyNfMwkSq4efaB49/vNt6KsYAUq3Av9LlHFBXeKO/AlWZFLSt bRxQ== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 130-20020a630488000000b003fc5ca10e2asi28715811pge.73.2022.06.09.02.42.39; Thu, 09 Jun 2022 02:42:51 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240884AbiFIIyG (ORCPT + 99 others); Thu, 9 Jun 2022 04:54:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242484AbiFIIxA (ORCPT ); Thu, 9 Jun 2022 04:53:00 -0400 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9FEB1447A6; Thu, 9 Jun 2022 01:51:47 -0700 (PDT) Received: by mail-ej1-f44.google.com with SMTP id s12so38888307ejx.3; Thu, 09 Jun 2022 01:51:47 -0700 (PDT) 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:from:to:cc:references:in-reply-to :content-transfer-encoding; bh=SXRFuRSOer0UTWqXklwZQzcqdPi/nxqTmlZiGWPV4ZU=; b=GYMHiulDbcN3cmGz4FKnX9FSbT75uZLGViASYny1A722tIGFEEL36aEleXraPN4uJr tNqPH3oGiJS0pA6vrdkyrKMIKWUoxQQqQ9vuEjh6EiNVwv5/xQz1GmBK+PkKSgP/h1x3 g+W84kya6l0P9v4e6k3yNJZPNi7VMLzRuQwwkUf6bYOkZf1ZNoKZuyaXMbA2ev4KO1xm 4Xrp57z9JHYR2wPjpEu5DGiw8Y+fu8ktnHFs4MBpqH31dxFOwB4Uj9nO2RJwAOtkLWOh XEyeU02HkBO0GWAhz7rjowdjOTmLulzZxrJz7F1yP6w1nofZzPb2T2AJNDQgana4Zs10 KUpg== X-Gm-Message-State: AOAM533jqAJRCcn1L1JNMe3KefB4NmWo4gfouYpYyNqqEgRZaHPUbbSk fnCDUiTs9XxQL5aE9G61MgWNFmK2z8li9g== X-Received: by 2002:a17:906:4787:b0:711:d085:88a3 with SMTP id cw7-20020a170906478700b00711d08588a3mr17209001ejc.118.1654764706280; Thu, 09 Jun 2022 01:51:46 -0700 (PDT) Received: from ?IPV6:2a0b:e7c0:0:107::70f? ([2a0b:e7c0:0:107::70f]) by smtp.gmail.com with ESMTPSA id w2-20020a056402268200b0042ddd08d5f8sm14680854edd.2.2022.06.09.01.51.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Jun 2022 01:51:45 -0700 (PDT) Message-ID: <926a95c0-3d0b-4dec-4894-3fd756d565a4@kernel.org> Date: Thu, 9 Jun 2022 10:51:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH 16/36] tty/vt: consolemap: check put_user() in con_get_unimap() Content-Language: en-US From: Jiri Slaby To: David Laight , "gregkh@linuxfoundation.org" Cc: "linux-serial@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <20220607104946.18710-1-jslaby@suse.cz> <20220607104946.18710-16-jslaby@suse.cz> <5bf366cc45334bb9a9c3d186ef8d6933@AcuMS.aculab.com> <9780cd63-5cf3-7ee0-4866-160b9de0a3e8@kernel.org> In-Reply-To: <9780cd63-5cf3-7ee0-4866-160b9de0a3e8@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 08. 06. 22, 10:11, Jiri Slaby wrote: > On 08. 06. 22, 10:02, David Laight wrote: >> From: Jiri Slaby >>> Sent: 07 June 2022 11:49 >>> >>> Only the return value of copy_to_user() is checked in con_get_unimap(). >>> Do the same for put_user() of the count too. >>> >>> Signed-off-by: Jiri Slaby >>> --- >>>   drivers/tty/vt/consolemap.c | 3 ++- >>>   1 file changed, 2 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c >>> index 831450f2bfd1..92b5dddb00d9 100644 >>> --- a/drivers/tty/vt/consolemap.c >>> +++ b/drivers/tty/vt/consolemap.c >>> @@ -813,7 +813,8 @@ int con_get_unimap(struct vc_data *vc, ushort ct, >>> ushort __user *uct, >>>       console_unlock(); >>>       if (copy_to_user(list, unilist, min(ect, ct) * sizeof(*unilist))) >>>           ret = -EFAULT; >>> -    put_user(ect, uct); >>> +    if (put_user(ect, uct)) >>> +        ret = -EFAULT; >>>       kvfree(unilist); >>>       return ret ? ret : (ect <= ct) ? 0 : -ENOMEM; >>>   } >> >> How is the user expected to check the result of this code? >> >> AFAICT -ENOMEM is returned if either kmalloc() fails or >> the user buffer is too short? >> Looks pretty hard to detect which. > > Agreed. The code is far from perfect. We might try to return ENOSPC and > watch what breaks. brltty and kbd (see below) would break at least: https://sources.debian.org/src/brltty/6.4-6/Drivers/Screen/Linux/screen.c/#L875 brltty apparently relies exactly on ENOMEM, increases buffer if that error is returned, and retries. So I don't think we can change that ENOMEM to anything else. >> I've not looked at the effect of all the patches, but setting >> 'ret = -ENOMEM' and breaking the loop when the array is too >> small would simplify things. That would break kbd for example: https://sources.debian.org/src/kbd/2.3.0-3/src/libkfont/kdmapop.c/?hl=154#L159 GIO_UNIMAP is called with zero count to actually find out the count... So apart from the original patch which checks the return value of put_user, we cannot do anything else. (Except decoupling the "?:" to make it more readable.) thanks, -- js suse labs