Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1olsRb-00019k-PF for mharc-grub-devel@gnu.org; Fri, 21 Oct 2022 09:52:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olsRY-00019W-B1 for grub-devel@gnu.org; Fri, 21 Oct 2022 09:52:12 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1olsRV-0004if-Lp for grub-devel@gnu.org; Fri, 21 Oct 2022 09:52:11 -0400 Received: by mail-pg1-x531.google.com with SMTP id q1so2589261pgl.11 for ; Fri, 21 Oct 2022 06:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=rs4p361wj2DR5b/fgw5hZR+qGW3/+gSjLikHONOsQqY=; b=dhxou0mOzvy7psLA4mRh/TuOnbSFAvZeczUcOUD1OSYGZBVHnzt1Uwwlp2RmiNzEJ2 N3ureOh6uJA13b8wbTGc+EKRcVNpTNmcQlIQ0Tzk3huFLdT9q9eu1yKslKLhpBnuZEgc DP1Q4Cp5uzVTGIjdJDglH1tA3AwejYsRgOT74= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rs4p361wj2DR5b/fgw5hZR+qGW3/+gSjLikHONOsQqY=; b=qp42dHcbGntJzObMr83m1ihmfoEx/hUSdu+daZRnt3rM/RCVJ9uDfr3csSEqWR7CIN S7dWmufJ2WgqB6T7BDYIixSo/utIAvOOvSXqLvbknlKqoyv/F0A+vOR9B0stNmQkNadp JZaMgwDuVFvDa8UQoix+QebuxTnKhM01uaqQYC3uHF1Ei0/4RebYvFOutfRUsuCKzoXp MCbPFt9I0xJ6pKCtryzlP6gf9rahS9JnEfCwl5qmndQh87U8Qqu4I+14rK3EEp2hZdWp oEAocaj04HlZo0/lRHxAq3KNJtJ8sH7+9uVPN/pqt02nMWDQJk0WmDEEXUrc2wEhEq/o 38Nw== X-Gm-Message-State: ACrzQf2ouowJfvDvh9TSfxHLVrE15geOIJlVs4UAFjA01ud0S/cRBClq no4xRVHLy5xiIGBSPgp+B4OcTw== X-Google-Smtp-Source: AMsMyM6diPmhZ5ozGMK+ENM4qnCOSdgqHeKYA+R9J/8oSygB4YegR2sKWn4H2raa8pSSTtgstA6CYg== X-Received: by 2002:a05:6a00:16c1:b0:563:177f:99ee with SMTP id l1-20020a056a0016c100b00563177f99eemr19603759pfc.7.1666360327362; Fri, 21 Oct 2022 06:52:07 -0700 (PDT) Received: from localhost ([2001:4479:e300:5b00:a1e6:6751:b596:2ac]) by smtp.gmail.com with ESMTPSA id a24-20020aa795b8000000b005627b3788b8sm15114339pfk.181.2022.10.21.06.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 06:52:05 -0700 (PDT) From: Daniel Axtens To: Alec Brown , grub-devel@gnu.org Cc: daniel.kiper@oracle.com, alec.r.brown@oracle.com, darren.kenny@oracle.com Subject: Re: [PATCH 2/2] video/readers/jpeg: Check next_marker is within file size In-Reply-To: <1666300274-2151-3-git-send-email-alec.r.brown@oracle.com> References: <1666300274-2151-1-git-send-email-alec.r.brown@oracle.com> <1666300274-2151-3-git-send-email-alec.r.brown@oracle.com> Date: Sat, 22 Oct 2022 00:52:02 +1100 Message-ID: <87y1t9jnct.fsf@dja-thinkpad.axtens.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=dja@axtens.net; helo=mail-pg1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Oct 2022 13:52:12 -0000 Alec Brown writes: > In grub-core/video/readers/jpeg.c, the function grub_jpeg_decode_huff_table() > has the variable next_marker which reads data from grub_jpeg_get_word() and > then uses it as an upper limit in a while loop. However, the function isn't > checking that next_marker is within the file size, so this check is being added > to the function. > > Signed-off-by: Alec Brown > --- > grub-core/video/readers/jpeg.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c > index 0eeea0e63..c0f95fbf9 100644 > --- a/grub-core/video/readers/jpeg.c > +++ b/grub-core/video/readers/jpeg.c > @@ -199,6 +199,12 @@ grub_jpeg_decode_huff_table (struct grub_jpeg_data *data) > next_marker = data->file->offset; > next_marker += grub_jpeg_get_word (data); > > + if (next_marker > data->file->size) > + { > + /* Should never be set beyond the size of the file. */ > + return grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: invalid next reference"); > + } > + This is a good idea. I briefly wondered why this didn't lead to issues detected in fuzzing. It'll be because the code reads byte by byte until we get an EOF and then the loop will bail. Your change is still good, I just wanted to double check that you hadn't accidentally found and fixed a more serious bug. The fuller context: while (data->file->offset + sizeof (count) + 1 <= next_marker) { id = grub_jpeg_get_byte (data); if (grub_errno != GRUB_ERR_NONE) return grub_errno; > while (data->file->offset + sizeof (count) + 1 <= next_marker) > { > id = grub_jpeg_get_byte (data); > -- > 2.27.0 > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel