From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 7BB9223E356 for ; Fri, 27 Mar 2026 14:41:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.42 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774622515; cv=pass; b=bRiD/O8E99jw21U4grOH5yu+2xKZ4Ez6R3e4powIBmRTSvJHFVfbn1f0m2o+V4pKh0QcCHVYzugJcwv0Y/2weeU7vmD5RyXFzHmLHcM277Q+tIMiknT7mp0h/Gjv7UlLohkAD4bNg9JOQUVNrIITKr5oP9hmRPYm4rIEl4OHoGE= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774622515; c=relaxed/simple; bh=ra8SpAj2LxpomhGKFZiGT3TPpxT/LmqHWkszliMnmQ0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Content-Type; b=dlPvIopnD4xc0hBfhOUMVg2fXRRMHJrm7FPb8Cqe4BpE5kxNU9IS2hxcY0owjJZ2xuufmfNMiuvjrxkHYNPDDzRZDe/N94FwdkBaAhqG5wj1CBXpRw34weeNzhgCxV2GdO0YmsJVpzqR86UN2Ydj07lmnlrGIlAckYMNmap+NaE= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=EWz6L4EE; arc=pass smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="EWz6L4EE" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-66a9a2187a5so3389819a12.0 for ; Fri, 27 Mar 2026 07:41:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774622512; cv=none; d=google.com; s=arc-20240605; b=lpIB3E49VtycVm48OiNUe3giQPGMg+oZkMXIk0OdLPk3ljQQHuNXTxlM+Jnb+tGwo5 1wtGaH1vCLHuPRSKKW8X03vLm+kl6EDoVCn+ZFbPB9yf6FZFx6Fok2EcbRGN1R1wN+07 JWifRDle3QN3tzpCwEIlQ+xecI5bJnSY9MnZF2jpp1TlY2kjptsSea5qX83mkctNiEZa DuJN4kOgSsFc/JWY0a3XyAoPIlebhQlrQodbrp9wWEQkAcgDGh35vdKOg1D/AbuqEEtt A5jMWPj+3avzqFg1hqUfyCctFdy1RO6kTuz71M7s3scS1EGZewAcvG1TBmsQTweSfLlT Eidg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=nugzbSmXYxH79Cp7ObFsyTKICHKOQ5VI8ykZIBcaifc=; fh=2O7irgfekt3dutQAcmt2uQ70wp6E5D1zxbRzsJmRc9c=; b=a4uCmE1SAdc/uM+HNA/VAop7czECnTFFxL2ySIbqE5bc16CY8cCxZG7F2OVNynpJYa qwqpSMePXXZ1/dCHN1mdqsE3L1IBoi7WCImcz3rQaGLHW503MinBNEUEdcQqMkanj4AW w+D7aioqhfsT71JPLhrBk4JrSN4Rukr6LtTyIwSUz0F5rUlEmb5xGvUnHqmdOQauz1Fe wxENTZjAbf+eZa7N1NAPS5E6pNsF+XdyXdKnO5t9U2x6FoGWT9s5Z6Qk6Vakxz3d86Qy 0FO+WqJJvsgrAg//NvtFi8/NvUczTKaYqI+55sYlmqgvv049OtnD/i9Tv2JzKtO4B+/6 k8YQ==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1774622512; x=1775227312; darn=vger.kernel.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=nugzbSmXYxH79Cp7ObFsyTKICHKOQ5VI8ykZIBcaifc=; b=EWz6L4EEnHAuNoGdeCDbxa1XejcdiFedr9O7NtNKbUkP6/P1bKZOjG9iXN8A1BMcPH FwE3t35I5+TpRrH6n3hF87UWjH3BSoEQx0MMP/x9UfXu0Gm4aiy0VUa3b69+x0eykJFD uFo6pklZQBPFrOXVlNizgpdADPHhTHGeCzs4Lbyum7it9Qpi9A0BkhtkQLWsOO0njOXr 7hbyhgV222Itd1jsKz22naw8mZHTVlo7xKh1375zP0Dpw97kaJ8vZamQc/9HaWS/orju gP6Ag1GLawYeq/CAjJ3J0pxLDqf+FpXGJWNhd3VQjTexHvmIVcLqgRrltGr/Fhv+Kjvs QFkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774622512; x=1775227312; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nugzbSmXYxH79Cp7ObFsyTKICHKOQ5VI8ykZIBcaifc=; b=kIdDdnHKAgqQ2IJ8uUZWnEpynQL4dVZJG8DWSYA//2bCPQ/zgN6+MjCQ2V8HwY4KKJ jMkr3BvlPJFQ6IPuzfdjYBqAPdBARyKuOHdsjFvLqnzKj7egtZdTOgFm7XeCi4JtLmOq VqnvW1+n7j/NyTeYVERDRq9xdDv09yWVOANIdVTgCsTxXdhSCA3e75T2a8blcHmKMjSq xFmWTArqtzqsI6/Gf4rbwUd1ighPAxw89D3oHOjqnNWI5n8CxwvYxJto55MIM7k79kfP FmI2SaOjX9gFtM1lEtevAIencC5LryKOJ5Y6loLZjJpB1xpzesAqQ6jB2ymPk/smwzHL ov/A== X-Forwarded-Encrypted: i=1; AJvYcCUYObnoR9RxILguHeLUl5lR/GCB4dHQPO5VuYlp+pLMMruhzD6Owz/6w05KFUEw9ZbYD1xlNazNonapmNc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0Noc/SsT1cinj6161C7qa/Db0YpM6BPZskdCwQyCiotQ52aPU MBvf7ORzXxQWP33QVBAmx2WNdu2fjamu1dKn7SK3i44ek9MCX5xaLjsp/aL7yKnKdllf+bs/8lc XbO54io5i6evKYWR4y3TnGK9Qng3hbDGC44hd83YAv5zwTRABf9bjqvY= X-Gm-Gg: ATEYQzwzYlk04RlSkvS2mLPg/dbNV4AtxlY1NTt9b3uALmv83b23lxCg+Ex8XYhRZm0 Lieoou/BGF4SpUyg+CH8pt5WN+e3qWlmtR1DgVOVrCfFwTm9H198BdHeS3xjZSsG1CQ7qvl1+n6 tYMt/tV5K2CIhGjFWpAVOpgUBAPJLulaXHQV+wQ88QNVQHTcZtW3gRHZW+QRbbUmaa343lNGT0k pc4M5POFsXSZmVQs5IyXTJ7YW2JmDX5uaIrEzOzDxply3nswAT3dWsqLA63eS+B3uI3ORMO5b2S q7bNEAY4WhWSAr/XMQvbW186+m3u1fxrVne4WA== X-Received: by 2002:a05:6402:354b:b0:66a:50c2:6bd6 with SMTP id 4fb4d7f45d1cf-66b28e7293cmr1686849a12.23.1774622511672; Fri, 27 Mar 2026 07:41:51 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260327033335.696621-1-pasha.tatashin@soleen.com> <20260327033335.696621-10-pasha.tatashin@soleen.com> In-Reply-To: <20260327033335.696621-10-pasha.tatashin@soleen.com> From: Pasha Tatashin Date: Fri, 27 Mar 2026 10:41:15 -0400 X-Gm-Features: AQROBzDQzt0n5uJUWlk0xXXs0sfRPTiMoyJTGbGyDBSSRc0CqylzPeBQcXHKLw0 Message-ID: Subject: Re: [PATCH v3 09/10] liveupdate: Make unregister functions return void To: rppt@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pasha.tatashin@soleen.com, dmatlack@google.com, pratyush@kernel.org, skhawaja@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 26, 2026 at 11:33=E2=80=AFPM Pasha Tatashin wrote: > > Change liveupdate_unregister_file_handler and liveupdate_unregister_flb > to return void instead of an error code. This follows the design > principle that unregistration during module unload should not fail, > as the unload cannot be stopped at that point. > > Signed-off-by: Pasha Tatashin > --- > include/linux/liveupdate.h | 14 ++++++-------- > kernel/liveupdate/luo_file.c | 14 ++------------ > kernel/liveupdate/luo_flb.c | 11 +++-------- > 3 files changed, 11 insertions(+), 28 deletions(-) > > diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h > index 73ca84de3eae..2ae27711ac41 100644 > --- a/include/linux/liveupdate.h > +++ b/include/linux/liveupdate.h > @@ -229,12 +229,12 @@ bool liveupdate_enabled(void); > int liveupdate_reboot(void); > > int liveupdate_register_file_handler(struct liveupdate_file_handler *fh)= ; > -int liveupdate_unregister_file_handler(struct liveupdate_file_handler *f= h); > +void liveupdate_unregister_file_handler(struct liveupdate_file_handler *= fh); > > int liveupdate_register_flb(struct liveupdate_file_handler *fh, > struct liveupdate_flb *flb); > -int liveupdate_unregister_flb(struct liveupdate_file_handler *fh, > - struct liveupdate_flb *flb); > +void liveupdate_unregister_flb(struct liveupdate_file_handler *fh, > + struct liveupdate_flb *flb); > > int liveupdate_flb_get_incoming(struct liveupdate_flb *flb, void **objp)= ; > int liveupdate_flb_get_outgoing(struct liveupdate_flb *flb, void **objp)= ; > @@ -256,9 +256,8 @@ static inline int liveupdate_register_file_handler(st= ruct liveupdate_file_handle > return -EOPNOTSUPP; > } > > -static inline int liveupdate_unregister_file_handler(struct liveupdate_f= ile_handler *fh) > +static inline void liveupdate_unregister_file_handler(struct liveupdate_= file_handler *fh) > { > - return -EOPNOTSUPP; > } > > static inline int liveupdate_register_flb(struct liveupdate_file_handler= *fh, > @@ -267,10 +266,9 @@ static inline int liveupdate_register_flb(struct liv= eupdate_file_handler *fh, > return -EOPNOTSUPP; > } > > -static inline int liveupdate_unregister_flb(struct liveupdate_file_handl= er *fh, > - struct liveupdate_flb *flb) > +static inline void liveupdate_unregister_flb(struct liveupdate_file_hand= ler *fh, > + struct liveupdate_flb *flb) > { > - return -EOPNOTSUPP; > } > > static inline int liveupdate_flb_get_incoming(struct liveupdate_flb *flb= , > diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c > index dd55e5e74d69..761e8f7cfc82 100644 > --- a/kernel/liveupdate/luo_file.c > +++ b/kernel/liveupdate/luo_file.c > @@ -884,25 +884,15 @@ int liveupdate_register_file_handler(struct liveupd= ate_file_handler *fh) > * > * Unregisters the file handler from the liveupdate core. This function > * reverses the operations of liveupdate_register_file_handler(). > - * > - * It ensures safe removal by checking that: > - * No FLB registered with this file handler. > - * > - * If the unregistration fails, the internal test state is reverted. > - * > - * Return: 0 Success. -EOPNOTSUPP when live update is not enabled. -EBUS= Y A live > - * update is in progress, FLB is registred with this file handler. > */ > -int liveupdate_unregister_file_handler(struct liveupdate_file_handler *f= h) > +void liveupdate_unregister_file_handler(struct liveupdate_file_handler *= fh) > { > if (!liveupdate_enabled()) > - return -EOPNOTSUPP; > + return; > > guard(rwsem_write)(&luo_register_rwlock); > luo_flb_unregister_all(fh); > list_del(&ACCESS_PRIVATE(fh, list)); > > module_put(fh->ops->owner); > - > - return 0; > } > diff --git a/kernel/liveupdate/luo_flb.c b/kernel/liveupdate/luo_flb.c > index f8348138de70..8f3c9c63e320 100644 > --- a/kernel/liveupdate/luo_flb.c > +++ b/kernel/liveupdate/luo_flb.c > @@ -492,21 +492,16 @@ int liveupdate_register_flb(struct liveupdate_file_= handler *fh, > * owner module (acquired during registration) is released. > * > * Context: It is typically called from a subsystem's module exit functi= on. > - * Return: 0 on success. > - * -EOPNOTSUPP if live update is disabled. > - * -ENOENT if the FLB was not found in the file handler's list. > */ > -int liveupdate_unregister_flb(struct liveupdate_file_handler *fh, > - struct liveupdate_flb *flb) > +void liveupdate_unregister_flb(struct liveupdate_file_handler *fh, > + struct liveupdate_flb *flb) > { > if (!liveupdate_enabled()) > - return -EOPNOTSUPP; > + return; > > guard(rwsem_write)(&luo_register_rwlock); > > luo_flb_unregister_one(fh, flb); > - > - return 0; > } A question from Sashiko: If the file handler is unregistered and freed by its owner, its dependent FLBs might still retain a stale pointer to it. When an FLB is later unregistered and calls liveupdate_unregister_flb() with this stale fh pointer, could luo_flb_unregister_one() dereference the freed memory and cause a use-after-free? No, there is no UAF possability here. 1. FLBs do not keep pointers to file handlers. The relationship between file handlers and FLBs is asymmetric. A struct liveupdate_file_handler maintains a list of its dependent FLBs in its flb_list. And, the struct liveupdate_flb only tracks the number of handlers using it and its position in a global list. It does not store pointers back to the file handlers. 2. Manual FLB unregistration: When a subsystem calls liveupdate_unregister_flb, it is responsible for providing a valid fh pointer. Since the subsystem typically owns the lifetime of the fh (a static structure in the module), it is the caller's responsibility not to pass a stale pointer. 3. Atomatic FLB unregistration during liveupdate_unregister_file_handler function, explicitly calls luo_flb_unregister_all(fh): luo_flb_unregister_all(fh) iterates through the handler's flb_list, calls luo_flb_unregister_one for each, which removes the luo_flb_link from the handler and frees it. This ensures that when the handler is gone, all its associations with FLBs are already destroyed. Pasha