Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp176650lqc; Thu, 29 Feb 2024 13:59:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUl+96ROedpZcRdzXhUzimWiHO3ktcme1vINoHhtybwbfu38CaICuYLJTNNG4mupjgM3izYoOyONHYLIRB5sFY9cgHlwP+sTQmqJzIiyw== X-Google-Smtp-Source: AGHT+IEtxRtUAMI2k2kfazdJsXmJj78bYTFL80O8bqOs8u6lcXoGAPN0EpKWUfJUNEn9/bf6Y3px X-Received: by 2002:a50:c943:0:b0:566:1694:7090 with SMTP id p3-20020a50c943000000b0056616947090mr129650edh.11.1709243946540; Thu, 29 Feb 2024 13:59:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709243946; cv=pass; d=google.com; s=arc-20160816; b=MO0+arlTV+uI3Zmv2Z4Ztlnb/ne13g9Z6PfEIyyu5XDfjU/dF8C1cpc+XlvL0qcvQz dMzkksWmi614CA/1YT3iScTy/Y9B5Rcwc666oWC31IcEOQwpF8hRhr+LGJku5/6feBjo brYWoYvcYxYqL4NroVjVyLDrXnY8QHySiCwu+FC5mSAMBnI139HvyzITZkzI6tBqC/Zx JCuiCbroPykrl2v733UlT3wgZtTk/gbN6jGSXjWZvGihCu06Ap2YLazm4xlAu8PEfPfZ +091LODskFQyoYMgbKcn9RgCsI5z1vh3N6xNiLiRuwPKGwUPt9yWw3vxM8voAezn8WVk S4jw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=DiJQ8IEdW2Jkk/S4jOTeOO3q8QRmk15ZcHgGmWobrwI=; fh=scrb9YhufrPqHzYrehJAZPm1kIM4FDccU65mCI5/QHU=; b=Wqj8q9X2OZY+6Vl3T4Vj4of0cQR34zG+MkrMRdIFbNVd3WCumS9OgzwOdUQTodnuiH tOJuyFKAjlHDE86ljAVYbAxpBrkXxZzKwxFgZVnJnkiWf6sC9xFjppEuJ+X2h7JhI1zJ CGgnFauy+vky1TwYRpRqs4hdmg70rF0RzSxe2+NAfIu/oBtgpjpft2PPmHNl3TqHognU SgHmn/d/0qr2ODAEzTtGRnt/QZcvf9oE9IeE7MEic5rP4qfbmxtZ74JkouHhsH4wM6nN 3x2dlSSNWlVx7wYrpAFPPJ5+MvUxiWd2ZCKdrEnfVnSW7AS7WN6Iz8tUjmQNlqqWlJLc DXlQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Vufomjse; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-87609-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87609-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h10-20020a056402280a00b005664aa9219esi941102ede.131.2024.02.29.13.59.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 13:59:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87609-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Vufomjse; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-87609-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87609-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3FE3C1F23AB7 for ; Thu, 29 Feb 2024 21:59:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 936C96D530; Thu, 29 Feb 2024 21:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Vufomjse" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0352B16FF46; Thu, 29 Feb 2024 21:58:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709243938; cv=none; b=i7Obq1iFF8iCkYCHxFVb1V6j1UIEw1fo9iSZ+ccMLQ3nr6gVAr98grd59uHI0SQ0DCfYUpv7Z5P7+Mr4nZUj/dXpYXvOzuwikL7cvnyHqgV4k0HzTNjElo3T4TR8o/eEBDQ4sDowsOyxmEb0g9YmrU0Mp6xHUszFUO6lLAiMDAs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709243938; c=relaxed/simple; bh=5JVabrlMLe/1NI62rmzy/ei3KAtCFMI1zLcwOM4J3wA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eZx7KXFi9bs9Z9QwfBwpTSyCX85p5KPjjO7gk501CTQdY475mE5ry5CemuPSTvNH8uLI5XxwqjOZDVGJNsszFV5EWj9NcXYY5akVUUjJQZEtQ6AXhV0SWCf8uN00LYis3KsR5pFLb3WIKY26p73mNDflmBNGot6I8qTLa0wClNA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Vufomjse; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 9AEDF40003; Thu, 29 Feb 2024 21:58:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1709243934; 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: in-reply-to:in-reply-to:references:references; bh=DiJQ8IEdW2Jkk/S4jOTeOO3q8QRmk15ZcHgGmWobrwI=; b=Vufomjser0fMBgkFugDyP7xz2NZDrANrKG05Os5lRiWQQXwpRfMzls1U5UVZfCj5mGCYba 5aJ3QYmmc8fc0/4bxjHolLYyp6+I0mYpkgOkagq1VAy9ei7hF5XdFt9KRU8p7qKO5AFnSI IDmHMn7xkIikioGrvhOglf1pB1piCcIgXRwijdx3iZwFVhiQWk0Z/Zc120AtPSiUql9bAZ 5Og6pScc2s5MeWAL+U4EWkNgFn//q4vYRkZ8AF6ALxhFwbXShvYnMej6r4x9QOp+qJYnwW VB/q3oYjxHjy6ekb6CGKYrGj8M6OBOg3WeuUyEmA5yDBbTs4iyxSNx8tLH8WUw== Date: Thu, 29 Feb 2024 22:58:50 +0100 From: Alexandre Belloni To: Nicholas Miehlbradt Cc: a.zummo@towertech.it, linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] rtc: fix uninitialized read of rtc_wkalrm.time Message-ID: <20240229215850a1990100@mail.local> References: <20231129073647.2624497-1-nicholas@linux.ibm.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: <20231129073647.2624497-1-nicholas@linux.ibm.com> X-GND-Sasl: alexandre.belloni@bootlin.com Hello, On 29/11/2023 07:36:47+0000, Nicholas Miehlbradt wrote: > If either of the first two branches of the if statement in > rtc_read_alarm_internal are taken the fields of alarm->time are not > initialized but are subsequently read by the call to rtc_tm_to_time64. > > Refactor so that the time field is only read if the final branch of the > if statment which initializes the field is taken. > While the problem description is correct, the solution is not because you have no guarantee that the fields have been initialized if ->read_alarm returns a value different from 0 So, instead of avoiding the conversion unless the final branch is taken, it should be avoided as long as err != 0. But, I'm also wondering whether there is actually an issue. mktime64 can be fed whatever value without bugging out and the value of err will be part of the trace so userspace knows that it shouldn't trust the value. So, what is the actual issue? :) > Signed-off-by: Nicholas Miehlbradt > --- > drivers/rtc/interface.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c > index 1b63111cdda2..f40e76d2fe2b 100644 > --- a/drivers/rtc/interface.c > +++ b/drivers/rtc/interface.c > @@ -179,6 +179,7 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc, > struct rtc_wkalrm *alarm) > { > int err; > + time64_t trace_time = -1; > > err = mutex_lock_interruptible(&rtc->ops_lock); > if (err) > @@ -201,11 +202,12 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc, > alarm->time.tm_yday = -1; > alarm->time.tm_isdst = -1; > err = rtc->ops->read_alarm(rtc->dev.parent, alarm); > + trace_time = rtc_tm_to_time64(&alarm->time); > } > > mutex_unlock(&rtc->ops_lock); > > - trace_rtc_read_alarm(rtc_tm_to_time64(&alarm->time), err); > + trace_rtc_read_alarm(trace_time, err); > return err; > } > > -- > 2.37.2 > -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com