From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 B3C687083C; Fri, 18 Sep 2026 14:05:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789740321; cv=none; b=CATjCm1X68wn/qtKAy9IWABuH6wki+/knoKvN3vLtpSVE4A79P2aPZQdxhatnTJxApYhCvKGkZp3oKTS+3gFCf4QsT94t7A6NNyKCCWYtGJsDyYI9WyVTBoNovLo/eZwM5ZQtSsGhSTgUg18BB5OXt886TWOO5KUNt4bvQ5X0zk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789740321; c=relaxed/simple; bh=s/HR6k8B/bprMhq7hLGt9L2HLK8FcTh20U4yll7NTIA=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=q4UFHcPiAaLHmPwZ4epx4Eb5pJzRT2YA4n1m3KVzk3UvrzzdzSS0dsSs9sOdMpXLo5WrcPS3kuR43OZCcpUr9p/IrwwnjL10UckKZc9hTHSvsMefuBu8/ssYeQrHdDpXVeHdeDVKFaE7DoMTMmEOqsxyttlecV9Fo81xKpIvuHg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=beyVZOwP; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=WYfGZ5SG; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=DuYVJ/oT; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=cKlYB4VI; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="beyVZOwP"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="WYfGZ5SG"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="DuYVJ/oT"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="cKlYB4VI" Received: from pobox.suse.cz (unknown [10.128.32.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 741CA21BF6; Fri, 18 Sep 2026 14:05:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1789740313; h=from:from:reply-to: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=cw2sQTRj94rPCgIFFNXnQKvsGOQ1j8esjJsv6P/ZsNE=; b=beyVZOwPEquU/iCxYxnBJ1u27LhJjspkUTZrbhUnomrK57nxTi4kd81oKt/t4SWjDSG6/h m6BxdMhzrMLmdNEsCYQmEISCr9UP0ZlJ5OZhUP8zvyqNFE/wdfMZyC0GXR+cN2Raotens5 6EJmcuHKjH7LSZEoB13TaCEotFWYF6U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1789740313; h=from:from:reply-to: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=cw2sQTRj94rPCgIFFNXnQKvsGOQ1j8esjJsv6P/ZsNE=; b=WYfGZ5SGHTP0ya9Ekr8imTiMCXzFUX1N8++94350e4IY6tY9+ZPGfSBGocIuzDl7pn8LlN pExKff5qMnNwIfCQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1789740309; h=from:from:reply-to: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=cw2sQTRj94rPCgIFFNXnQKvsGOQ1j8esjJsv6P/ZsNE=; b=DuYVJ/oTyeU7F62cWw6sFFKA63OLqR3fCqUIsyebhNAxxoRdIZjJeK6R0F8BbTU7U/rv4R isBbQ+rwoatTSETObkZi0cuLnEWakwTUHJGoI21SrSOEaKCCFV/91vbAt00qTIferPZGwv knx3OQDu9SXizla5c4DwAlLZpsat72A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1789740309; h=from:from:reply-to: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=cw2sQTRj94rPCgIFFNXnQKvsGOQ1j8esjJsv6P/ZsNE=; b=cKlYB4VIopc2xIxKW5hp+JsZCiQulAaV0BwRlNVxCQ9k2Vo7WJ1xMtDjrtjjrFposLr08z 5f3JP/O4sUHlZeBQ== Date: Fri, 18 Sep 2026 16:05:09 +0200 (CEST) From: Miroslav Benes To: Petr Mladek cc: Harry Hsu , jpoimboe@kernel.org, joe.lawrence@redhat.com, jikos@kernel.org, live-patching@vger.kernel.org, shuah@kernel.org, song@kernel.org, linux-kernel@vger.kernel.org, sashiko-bot@kernel.org Subject: Re: [PATCH v4 4/5] livepatch: Clear relocations when klp_apply_object_relocs() fails In-Reply-To: Message-ID: References: <20260908120325.299649-1-pmladek@suse.com> <20260908120325.299649-5-pmladek@suse.com> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) 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 X-Spam-Level: X-Spam-Score: -4.30 X-Spam-Flag: NO X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; MID_RHS_MATCH_FROMTLD(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; RCPT_COUNT_SEVEN(0.00)[10]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_CC(0.00)[gmail.com,kernel.org,redhat.com,vger.kernel.org]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[] On Fri, 18 Sep 2026, Miroslav Benes wrote: > On Tue, 8 Sep 2026, Petr Mladek wrote: > > > When a module is loaded, klp_module_coming() updates all enabled > > livepatches. If an error occurs, it delegates cleanup to > > klp_cleanup_module_patches_limited(). However, this cleanup loop skips > > the partially updated patch, leaving any changes made prior to failure > > unreverted. > > > > One unhandled failure path occurs inside klp_apply_object_relocs(). On > > architectures like x86_64, apply_relocate_add() performs a verification > > step using memcmp() to check that memory contains the expected relocated > > or zeroed value. If relocations left behind by a failed patch are not > > cleared, subsequent patch operations or reloads can fail this validation. > > > > Introduce klp_write_object_relocs_limited() to unwind and clear only the > > relocations that were successfully applied before klp_write_object_relocs() > > encountered an error. > > > > There is no need to clear relocations for other objects in the failing > > patch because klp_module_coming() operates strictly on the specific > > module being loaded. > > Hm, I spent some quite time on that and I am not sure if I deciphered > everything correctly. > > It seems to me that all error handling in those paths you are mentioning > above is correct and the only problematic thing is that > klp_apply_object_relocs() in klp_init_object_loaded() returns ret > immediately which leaves partially applied relocations in case of an > error. Following calls in klp_init_object_loaded() go through err: label > where klp_free_object_loaded() is called which should be fine. > > Is it correct? > > Wouldn't be better to be somehow consistent and clean up right in the > error path of klp_apply_object_relocs() call in klp_init_object_loaded() > similarly to what is already there. After all we want to clean the object. > > But I also see why you want to do it this way. It only seems more fragile > to me. And only now I realized that I checked with 5/5 already applied by mistake. The above still stands though and at least I reviewed 5/5 as well. Miroslav