Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3248925ybf; Tue, 3 Mar 2020 02:25:46 -0800 (PST) X-Google-Smtp-Source: ADFU+vvjGM08hNykmGSo2c04lDg2V2v13xZxTwsYI8x10xBX4hyor9Pgt30rstQtMjpXPD7YN+kc X-Received: by 2002:aca:889:: with SMTP id 131mr1879515oii.3.1583231146112; Tue, 03 Mar 2020 02:25:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583231146; cv=none; d=google.com; s=arc-20160816; b=Pkm6fXAHK6qkJnwZBrljlBbO6/hPrJNe7EvlV7tPYkkVIIh6G+PKZ/2P8PSYa08FwH yfkNMQ0uus5UBqjoud5VO08umZ4J2FD36Mvn8QZZ335/+gjuMOQnkiZICmzqp+pZrbFa Bzsgd6Jid7DVZH5vHgTLEqpjzScaC9QKiI2SfXccwIOGoygSRAXygeNg8AnaNWCWO4dd c/aHsnzGgaUZvE52Sp6pcU6+abaXk69cVzS0SKjOvERijGjlF+LSveqL5n2nPhAXU+0B WLvVBBkiznAIWBB7u109kR6TThzvHxxFjT7KiiXZkt8nZW0kXzNrI22lrDsGhL1CcNAd t8pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature; bh=Y9OskcRkJBB13zwLLGMfs2S2+SpY5k0BUryUkH7intc=; b=wKrZba4wIiSt8q3tUIlwHYkS/qxD1RnG5n+1hpzt6m4t3OEWB+fZKVPU+cDiStAy3b 8+AVD6dYfLWG53wLHz0NLwc/z7kpFa78ET1gnzDnupo+cK31lV/9z2rQ1QWHbL+4V0Ky vfSRklJZ5r9dhw+86odh2qtzhuBAXTPt1G1AZ5ntUfOJ1nhNn2aJHaT89ANe8vcnIP/a tILyAsFMiW3DjWfda/f/pbtFBjpvu1L1NkLDyPJdeweFqGMMfTZeycPikhf2KeqfI9u7 AQz5BEItPbsqIXgLuAngJyNli/97f4NFDqX+b27ACO8ARYB6rlf/X+3b3o6C5RVfakpU uRKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="QZJ/Yxla"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m5si8147622ote.187.2020.03.03.02.25.34; Tue, 03 Mar 2020 02:25:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="QZJ/Yxla"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728630AbgCCKZE (ORCPT + 99 others); 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