Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1ifl3F-0005Bq-Mh for mharc-grub-devel@gnu.org; Fri, 13 Dec 2019 08:32:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33679) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifkWp-0001AP-7K for grub-devel@gnu.org; Fri, 13 Dec 2019 07:58:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifkWm-0003PV-0U for grub-devel@gnu.org; Fri, 13 Dec 2019 07:58:41 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:36363 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ifkWl-0003MI-Ha for grub-devel@gnu.org; Fri, 13 Dec 2019 07:58:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576241917; 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=b9VSUdKWho0AsMY5EAuNCRxldiXE6vz+eRj4A1RpznE=; b=imkRtc3sWgYdBrhPcLnjFB/he8/GKgZ86VSqeaJ3GMPQjio6YUbEeK6MdiM52skpfLGhFm t0gI1ok5BFwpNj5UlEOK2r/XaYoVimEDwtUcXjBYNuPNkfe/CBgBJly2r6ALznwNwrOg5F mM36BivM5/qd4frsgDOnq9TArAvkrPQ= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-5-hsX-C1z0N3GiT1AuWpWuHg-1; Fri, 13 Dec 2019 07:57:30 -0500 Received: by mail-wr1-f70.google.com with SMTP id 90so2537467wrq.6 for ; Fri, 13 Dec 2019 04:57:30 -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=b9VSUdKWho0AsMY5EAuNCRxldiXE6vz+eRj4A1RpznE=; b=PupWwxSSyxvmZ06kLhtnetfX18T4mdD/G2EfxXsBkWckDf5E5YaqL6TBv44B7aZn4U XjAb1aZB/+ecJLjiUfcYTjW3uTmjDVzy8cq6nCu0Js8whMtSqkCuUZPxRyKMZ6zsuP3T 2tthoDq8OpGmK49z1rK7l52h6P1rq0QrsCQ/oZhDCGBOnBH35u4La7Rm6cyTsFhom5nf ayE+tVSSmO0O1ECjINI3AEZ3fQmUAFrU5Dbz+WyTp0Gamv/W69DpUAaxzT3qk7OeDYLe 20+TDf1hhCWT4dh66uus7wr2LzqlK94UatHTmKvtgyC4LumSakChycqj8MXsaTa+sX4H 20HQ== X-Gm-Message-State: APjAAAVgBFadFDAnXGHqa2kS/4voFfjl1OJ96Eh89yy9w6eCPMfzhbdQ 8QVRsUenfXQ47p/fuCfNUmPWyI19MZ7Zm7WZPG/vH/4oXMsK3ZwgnoXIvuJwVtSK4ZGQWIrnH57 N1A6gDD6OGZg= X-Received: by 2002:a5d:4847:: with SMTP id n7mr12782925wrs.30.1576241849424; Fri, 13 Dec 2019 04:57:29 -0800 (PST) X-Google-Smtp-Source: APXvYqyooJsG59h/SK6I3qzEzqYCu18nX3AX3vzKAV9jTMjSRqTrZNGY7kFwDuyC2i72yIcBNrfkKg== X-Received: by 2002:a5d:4847:: with SMTP id n7mr12782893wrs.30.1576241849183; Fri, 13 Dec 2019 04:57:29 -0800 (PST) Received: from [192.168.1.14] ([90.168.169.92]) by smtp.gmail.com with ESMTPSA id q15sm9897425wrr.11.2019.12.13.04.57.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Dec 2019 04:57:28 -0800 (PST) Subject: Re: [GRUB PATCH 1/1] loader/i386/linux: Fix an underflow in the setup_header length calculation To: The development of GNU GRUB , Daniel Kiper , linux-kernel@vger.kernel.org, x86@kernel.org Cc: bp@alien8.de, eric.snowberg@oracle.com, hpa@zytor.com, kanth.ghatraju@oracle.com, konrad.wilk@oracle.com, mingo@redhat.com, phcoder@gmail.com, rdunlap@infradead.org, ross.philipson@oracle.com References: <20191202172939.29271-1-daniel.kiper@oracle.com> From: Javier Martinez Canillas Message-ID: <74fdf9ed-814b-0fc8-d405-79eb1011b9ee@redhat.com> Date: Fri, 13 Dec 2019 13:57:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20191202172939.29271-1-daniel.kiper@oracle.com> Content-Language: en-US X-MC-Unique: hsX-C1z0N3GiT1AuWpWuHg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-Mailman-Approved-At: Fri, 13 Dec 2019 08:32:11 -0500 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Dec 2019 12:58:45 -0000 Hello Daniel, On 12/2/19 6:29 PM, Daniel Kiper wrote: > Recent work around x86 Linux kernel loader revealed an underflow in the > setup_header length calculation and another related issue. Both lead to > the memory overwrite and later machine crash. > > Currently when the GRUB copies the setup_header into the linux_params > (struct boot_params, traditionally known as "zero page") it assumes the > setup_header size as sizeof(linux_i386_kernel_header/lh). This is > incorrect. It should use the value calculated accordingly to the Linux > kernel boot protocol. Otherwise in case of pretty old kernel, to be > exact Linux kernel boot protocol, the GRUB may write more into > linux_params than it was expected to. Fortunately this is not very big > issue. Though it has to be fixed. However, there is also an underflow > which is grave. It happens when > > sizeof(linux_i386_kernel_header/lh) > "real size of the setup_header". > > Then len value wraps around and grub_file_read() reads whole kernel into > the linux_params overwriting memory past it. This leads to the GRUB > memory allocator breakage and finally to its crash during boot. > > The patch fixes both issues. Additionally, it moves the code not related to > grub_memset(linux_params)/grub_memcpy(linux_params)/grub_file_read(linux_params) > section outside of it to not confuse the reader. > Maybe you should add the following tag? Fixes: e683cfb0cf5 ("loader/i386/linux: Calculate the setup_header length") > Signed-off-by: Daniel Kiper > --- The patch looks good to me. Reviewed-by: Javier Martinez Canillas Best regards, -- Javier Martinez Canillas Software Engineer - Desktop Hardware Enablement Red Hat