Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 73A533191D6 for ; Thu, 26 Mar 2026 09:34:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774517675; cv=none; b=OfZhE3hvZK+HO3JJ2/1n1F7F0Yj6mjCg4AqHPkHaakAC42uqjLidgaEKUszDgtI9h2T78xo1XC5kQY3tIovwhW0WyuTi3CclH7tt/Gcn1RfV+G7xZAHhDnFFJWFlYSpnpTuuJrdzIQcQg0Qud0otsqo+Jhsx7kAs5vVwV25L21Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774517675; c=relaxed/simple; bh=e4DftvVAt2KEVNS+8CzUB48oZeQrkwBSxbj0+lmLlJY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FDGkMVzZ0xE09XF89b76GRKEp/xeU8Qq2Zox1RyNQNVlsanIUjZKKu+04RHuCnfmqfwTHRW+Y9/z4R4AF1fBfmC8Uvnk3K0sslEHH92V+pcZzRgWY84U1C6ZQxMKMf+lckhXO4yEDFcYlkQwRoPWaN0U/qRP05bARxoA/fIUDZ8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=eujknqnu; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="eujknqnu" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-43b4915161fso651755f8f.2 for ; Thu, 26 Mar 2026 02:34:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1774517672; x=1775122472; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=pXdqB8AODLvAIjp+M4jmri5zo3s2GpGdvCRjRsxtOgM=; b=eujknqnudAXdfiP7TOB3GmsAnERTXo0mgJn602sx/tVJeAlZER7X35HKBc2BjgOmyL oKGoN2R8zlHdySw3HjlnsYxvP3vzCYX2I9FRVlbtcQAhy21PpJC1PNIdESmsDwlCbPkt +XJGUJ6XmeO6eoMNKfmr0OziPXS0fScf55tfL6zQrQyD5y0qBYdKNguKGBQNxSPGBv1X pET1RI7NmSMT4AtvWh4VuSjUr9yAubRqpy+Cy4OGRQQIlPK32moD6ZLEJdTl5COAzq0l YwwTMqQeCTNoxWOosr29QXiJqwWWBouxhPnfBmeqJDav/OPR9iQs6tQsIBkpnZS6Djp+ HejA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774517672; x=1775122472; h=in-reply-to:content-disposition: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; bh=pXdqB8AODLvAIjp+M4jmri5zo3s2GpGdvCRjRsxtOgM=; b=ggpMNhVtjU253kDbD+yA4w7oxqzupR3vi6yVcZydTJ1AlgQFpZbkSmiCSN6ND50QHQ s8pUCWqmbmLrsYDZh3JwKxrBnAc4yR7T5h6qHpFRGZZgLY0rldQBcgeeVzkxObU4gYio ftqWuoTDfgHgYyK3oAUq35lI2UkXWujZFvffWps6C8ex1r2p9rN1RyImG/BFxJHjSb2j s6cTu9wgD4Fy1jyqmYNGawawX/HSj9PyB57t4xkjxzLBoBeAypLcAxEbddUZxmeYyvaV gjaqWN0XsUlW79K94np2EbOu9WiT+WncTy0D8Mumc3LXanTO5L9kgDoH4750fTYnb2zD a7xg== X-Forwarded-Encrypted: i=1; AJvYcCUIUYtD3hnvuuUUAGnhTWyZ0fRY4g8WUyrcS8FrcDdvvhElI5oau1JPw6ipPUoWLHCK+ASH/HM4empbhdc=@vger.kernel.org X-Gm-Message-State: AOJu0YwLHeQ83227adYf1J98qY1K8bicMJBXy9BKDPMItEcOAsKlSFuQ 0OaAAel+QhGSOuiIJ79QqVd5FIFQf4tFFJLiSD5abHqAkS0jwjtg7wB+KMCTzG5T4T8= X-Gm-Gg: ATEYQzwgXvCMHtslmVOhZBzns56ThSNCclS3h/uTkkHyD8w81kabrCzWcC/RY2EaFpM xrWi00IIuPNQw2xgg/j815QL1hoYo6LJZ64y97IL9oFpKooufP16U4M4hLwLa3KoC4+GN3Mvag9 E3TL3HQAMyfugvXk1DP6K2bclHgaPdgxcnN1z1C8WU67yvqZYbZ6C8TsDIGIa6AIpJcfXAuPJiw i91CxnXfx5XlcwGa3AhbohpRN/wUI6TCDQ1jFlu74TTBD1y99W6sFHu6oxY/WkMYlTU89zxmxN0 Tldqk7Zvj4X7vIhl8olxAXS0pNl81PDstQ0lRNpy+VT2UqKO/wDwI0MHUcWI5cVtdIQDQkMdRXb y3++EYdj+jANKyqbspveX5H3BfjC/ksbQPJcKkxxCn2UZR+5QIHmzw0CdYYrcnCWjZATHdCmw1f 0qv237nc3YC56xJtD1tJrG+qswFqWeeAHxQmSe X-Received: by 2002:a5d:64e6:0:b0:43b:4ae5:d7c8 with SMTP id ffacd0b85a97d-43b8899530fmr9671229f8f.2.1774517671717; Thu, 26 Mar 2026 02:34:31 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b9192e3f9sm7355025f8f.7.2026.03.26.02.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 02:34:31 -0700 (PDT) Date: Thu, 26 Mar 2026 10:34:29 +0100 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , linux-kernel@vger.kernel.org Subject: Re: [PATCH printk] printk_ringbuffer: Fix get_data() size sanity check Message-ID: References: <20260319134955.185123-1-john.ogness@linutronix.de> <87fr5o570i.fsf@jogness.linutronix.de> 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: <87fr5o570i.fsf@jogness.linutronix.de> On Wed 2026-03-25 15:22:29, John Ogness wrote: > On 2026-03-25, Petr Mladek wrote: > >> --- a/kernel/printk/printk_ringbuffer.c > >> +++ b/kernel/printk/printk_ringbuffer.c > >> @@ -1302,10 +1302,6 @@ static const char *get_data(struct prb_data_ring *data_ring, > >> return NULL; > >> } > >> > >> - /* Sanity check. Data-less blocks were handled earlier. */ > >> - if (WARN_ON_ONCE(!data_check_size(data_ring, *data_size) || !*data_size)) > >> - return NULL; > >> - > >> /* A valid data block will always be aligned to the ID size. */ > >> if (WARN_ON_ONCE(blk_lpos->begin != ALIGN(blk_lpos->begin, sizeof(db->id))) || > >> WARN_ON_ONCE(blk_lpos->next != ALIGN(blk_lpos->next, sizeof(db->id)))) { > >> @@ -1319,6 +1315,10 @@ static const char *get_data(struct prb_data_ring *data_ring, > >> /* Subtract block ID space from size to reflect data size. */ > >> *data_size -= sizeof(db->id); > >> > >> + /* Sanity check. Data-less blocks were handled earlier. */ > >> + if (WARN_ON_ONCE(!data_check_size(data_ring, *data_size) || !*data_size)) > > > > The check of "!*data_size" is wrong after sizeof(db->id) subtractions. > > It is not wrong. It is checking something else. Good point! > > The question is whether we still need it. As the comment says, the > > data-less block were handled earlier. And it seems that data_alloc() > > explicitly creates data-less blocks when the given size is 0. > > And prb_reserve_in_last() only allows to increase the size. > > > > IMHO, we could remove it. Wrong values will be handled by the above check: > > > > /* A valid data block will always have at least an ID. */ > > if (WARN_ON_ONCE(*data_size < sizeof(db->id))) > > return NULL; Ah, I have missed that this earlier check won't catch it because it is '<' and not '<='. > > A zero size datablock which is not handled using the explicit > > data-less block is not expected after all. > > Well, the point of the WARN is to catch when things are broken. If for > some reason a data block of textlen 0 exists, it is a bug. I think we > should still catch it. I do not know if there are places in the code > that assume if it is a data block, it must have a textlen > 0. Probably > not, but still, it should not exist. IMHO, there is no function which would expect that a data_block must have a textlen > 0. It just should not exit. Because zero size data blocks are handled special way. So, just to be sure that the new code works as expected. Note that the moved check: /* Sanity check. Data-less blocks were handled earlier. */ if (WARN_ON_ONCE(!data_check_size(data_ring, *data_size) || !*data_size)) return NULL; warns only when data_check_size() fails. It just quietly returns NULL when *data_size is zero. If we really want to warn. Then it would make more sense to change "<" to "<=" in the previous check before the subtraction. I do not have a strong opinion. But I tend to add the warning because the zero size is not expected at this stage. Well, we could do it in a followup patch and keep this on as is. Best Regards, Petr