From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E83B348B368 for ; Wed, 19 Aug 2026 16:44:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787157874; cv=none; b=STvGyBNHsI/VqLnrnDIDpIFgHTW1HgSwcLXmE0r0ZulNg1iIOd8Coa2p6ixJ1UddSnut6osv9XnlnH93c+2JSga1mvOhCYMSil35NOBJOAYi0o16G/zY9unBwNB1nspfMW6Z4V09SywfBV84mnsXVGcQRk0vWjfsxXdnNAQsrDk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787157874; c=relaxed/simple; bh=EoEAV7ejpSZmFcizF6/IsRWD8DS5esh3O+yCY1FlMaA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=P2XgFAEkyF9jRb68/Ep6+gJsRBdEWTBznJ7xOyIMhWxDzi6ZHlp4KSHQWwiyCFUjIhRMX+trRWlZBdfda0LzG0YehSch8n7DTtYU2gihaqTUg1RRyOKlzobUEsMEqZRgFsDYgdImvNJjlU+AL8DYBbm/vdiJoTX62Gu8wrQhO84= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=PNhoL/hJ; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="PNhoL/hJ" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-38125cebfdaso2033038a91.1 for ; Wed, 19 Aug 2026 09:44:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787157872; x=1787762672; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=yUEL7Dgw3Ry1NoMw4a3dL5pN8hzybwWwVDY4tsypHy0=; b=PNhoL/hJ18e8GzZaMZubgsLB+q6DTppt3JgF1Qamz6G9PF5BvaUfcWaa3dQTDm7MM8 ZRTrfq+DExEBoQpruWtV84dNDm3ICJTu5215Rtf8xsbEzig62XWzDUtOT51Bd/QNZWrZ 6M5eXPNLTYuhNLfjvtGNPiN1mwfLzMSi4bF+pnmB0bQXy7nvyoqFzB0ss2SHNWqeQGwi +jLP0+p0uPmX2Ibpvyz1zV7sVindmU7eIHXbu3ZIams7yqVtpVcOjsTLL9r4aH02yQ1O 78RTZEmPrhVDL8/H0L1a/mnrNV8ecKMpSkma3nGPqrtPKekYno5zPMriWFYjLZnJ8Tw7 j1HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787157872; x=1787762672; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=yUEL7Dgw3Ry1NoMw4a3dL5pN8hzybwWwVDY4tsypHy0=; b=g1w5qZWE818JgQSItyxvuQmFTU7naXzmKFFLHzHf4x7wNCGDpVIDpw16PUdi9ndWQr GjLmpwTbBobSQeEZWNwQwCTN2bcgr+CsWIPKbh9zbIGYrWtH85nnZ/WNv7UqKqqZ7MD5 zn2WvmVa5xVhOridheeGR6D0nCNenLkRV5kJ7+mGxK47XhYuPxzoGfJCUGETC8BroNXC 5FlKsGQiO00kLiH8hqEb5ql0hj3BG9z8Sb90NWIKnRvsOAF3roT/69FZU873ZMTDYJ4G MJmgpYIsWyqfeajMojgNUj7sf/aMhsvvZnhzCWFN70Tzzo1X1OSFZMsvi0VS4AxpNOdv //ug== X-Forwarded-Encrypted: i=1; AHgh+RoaDzOJ24DKrap86MJFAgyBElx5S/jvbzWqE3uyGXT8sTUlSECo9K5GcHFV7SIBE5O6ehunFjufMyMU2Qk=@vger.kernel.org X-Gm-Message-State: AFuF++miCEGSVryHO1hRNcBnR8wafDq7tr1oHmTdEFUJM+PbgrcsZ//u bvJTsjwsgWzvNk6vvQCZvbyjZ+SSMo2ERI0dUq0tG7NaMGh+ee5eqvMesb04XyXC09Q= X-Gm-Gg: AR+sD12wPSHk2GzdGHabbmSurAtM3aWwnja6QiOGWa9EoeX0TwsCuZEHaTN0O8h49lN XwGGm8dSOggCsfKi7xpZ27he4Y2HQ+gmlAaD0QziF94fF7jaWYmKbrx4NVDD75r74o/J2gbTR1t 4hIse5zCTjsCCJ/Q+6vcbiyGs+WPOsam0cHz5xUwj/99MetwHgkS2jbRA2olf04965MjM1RvwIM 7ZCo1ujTZMVEF2zsZYYnN7rr1jeMob+WzYZOsQajepUaCv2RNtDKPOz4rwNi/OMHn9vLn1MlDE9 j1z5mMwxhtfVrIKzxveaEkrKmulr9yrEc+06oL9Fs9jk/OjO2wicVQ0fr6ylWczYBx6sFJ3WvbQ vMqPH6FESgWvr1ZBCO5PgEc0xfB4sPPPZd3zpFJI1Hh5gNzUSfFeuV5E9D9qm9hF7205Ba07ByH 4lOD20J2n2KmyS++Zszb1dTjvLehDlfTFIUCMbsMPcaYYWs6XlPn0bk804A8l1YQMA X-Received: by 2002:a17:90b:3a05:b0:38e:bbf1:de34 with SMTP id 98e67ed59e1d1-39580aa6b77mr11612863a91.7.1787157871904; Wed, 19 Aug 2026 09:44:31 -0700 (PDT) Received: from p14s ([2604:3d09:148c:c800:97bc:8ed5:dd4f:e433]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3957f96cd4asm3436661a91.3.2026.08.19.09.44.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2026 09:44:31 -0700 (PDT) Date: Wed, 19 Aug 2026 10:44:28 -0600 From: Mathieu Poirier To: HyeongJun An Cc: andersson@kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] remoteproc: elf_loader: bound the section header table Message-ID: References: <20260724025322.2341205-1-sammiee5311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Aug 19, 2026 at 09:15:27PM +0900, HyeongJun An wrote: > Thanks for taking a look! > > On Wed, Aug 19, 2026 at 1:42 AM Mathieu Poirier > wrote: > > On Thu, 23 Jul 2026 at 20:53, HyeongJun An wrote: > > > + /* find_table() reads the header at shstrndx even with no sections */ > > > > Right, but if there is no sections, @shnum in find_tables is 0 and not > > arm is done. > > The loop is skipped, but there is one load before it: > > :266 name_table_shdr = shdr + (shstrndx * elf_shdr_get_size); > :268 name_table = elf_data + elf_shdr_get_sh_offset(class, name_table_shdr); > :270 for (i = 0; i < shnum; i++, shdr += elf_shdr_get_size) { > > :268 reads sh_offset out of the header at index shstrndx, before shnum is > tested at :270. Both callers, :336 and :380, reach find_table() without > checking shnum. The value is unused when shnum is 0, so it is a 4 or 8 > byte read past the buffer and nothing worse. > > > > + shend = size_add(size_mul(elf_shdr_get_size, (size_t)shstrndx + 1), shoff); > > > > Why the shstrndx + 1? > > To hold the header at index shstrndx the table needs shstrndx + 1 entries. You are correct. I would assume that if e_shnum is 0, then e_shstrndx would also be 0. If it isn't the case then your patch is valid. I will queue it when rc1 comes out. Thanks, Mathieu > It is keyed on shstrndx and not shnum because nothing here requires > e_shstrndx < e_shnum. > > > Also, there is no point in doing this check if @shnum is 0. Please > > move this block in the "if (shnum)". > > The check it replaces, :95, sits outside any shnum test today, so moving > it in loses what master already has. > > If you want it inside, the way there is to drop the read: > > if (!shnum) > return NULL; > > at the top of find_table(). The loop already falls through to return NULL > at :313, so it changes nothing today, and the bound can then go inside > "if (shnum)". > > I am happy to do either. Let me know which you would prefer for v2. > > Thanks a lot!