From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F189CC3F2C6 for ; Tue, 3 Mar 2020 10:25:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C8EC4214D8 for ; Tue, 3 Mar 2020 10:25:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QZJ/Yxla" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728650AbgCCKZE (ORCPT ); Tue, 3 Mar 2020 05:25:04 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:40924 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728480AbgCCKZE (ORCPT ); Tue, 3 Mar 2020 05:25:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583231103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y9OskcRkJBB13zwLLGMfs2S2+SpY5k0BUryUkH7intc=; b=QZJ/YxlaVzHTlgloSVxjgx26dL0Zye4fr+y7Y5+aJYjUiS8WmhrZPXM4JpGR3YWe/YMPhA 6LDENtT5ey7735Mn1XbmJHafUnetKDBW1pCu+LE0WOjq5dwUoaPAgdtW9Yi+t7ZbdVGbnS 20EofHX/TSKePfYfsLUmOnxJO9ZoPOI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-269-Mq5NpSpDOvCPhq4vNA4ahw-1; Tue, 03 Mar 2020 05:24:59 -0500 X-MC-Unique: Mq5NpSpDOvCPhq4vNA4ahw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A808D800D50; Tue, 3 Mar 2020 10:24:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9CD0160BF3; Tue, 3 Mar 2020 10:24:58 +0000 (UTC) Received: from zmail21.collab.prod.int.phx2.redhat.com (zmail21.collab.prod.int.phx2.redhat.com [10.5.83.24]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 90B6686A00; Tue, 3 Mar 2020 10:24:58 +0000 (UTC) Date: Tue, 3 Mar 2020 05:24:58 -0500 (EST) From: Vladis Dronov To: Ard Biesheuvel Cc: linux-efi , Linux Kernel Mailing List Message-ID: <358842423.12639861.1583231098544.JavaMail.zimbra@redhat.com> In-Reply-To: <1980156503.12639063.1583230452485.JavaMail.zimbra@redhat.com> References: <20200303085528.27658-1-vdronov@redhat.com> <1980156503.12639063.1583230452485.JavaMail.zimbra@redhat.com> Subject: Re: [PATCH] efi: fix a race and a buffer overflow while reading efivars via sysfs MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.40.204.56, 10.4.195.30] Thread-Topic: fix a race and a buffer overflow while reading efivars via sysfs Thread-Index: a9pXAtMcyqvelpyZViw1cEjneZdMYYgMv25R X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, Ard, all, > > Wouldn't it be easier to pass a var_data_size stack variable into > > efivar_entry_get(), and only update the value in 'var' if it is <= > > 1024? > > > > I was thinking about this approach, but this way we still do not protect > var from a concurrent access. For example, efivar_data_read() can race > with itself: Oh, indeed, this race is not possible the way you sugget with a var_data_size stack variable. Unfortunately, AFAIU, the read/write race stays: > ... efivar read functions still can race with the write function > efivar_store_raw(). Surely, the race window is much smaller but it is there. > I strongly believe we need to protect all data accesses here with a lock. Best regards, Vladis Dronov | Red Hat, Inc. | The Core Kernel | Senior Software Engineer