Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp906603rwb; Mon, 26 Sep 2022 07:20:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4NY/KyuZxULBkbYo3jbZu88L+Eqb+Ipcp+ZCbJm2Mgj4CbG77xnpbg4KL2o0pBC8WH8pQV X-Received: by 2002:a17:906:5a5a:b0:770:86d0:fd8 with SMTP id my26-20020a1709065a5a00b0077086d00fd8mr18622733ejc.164.1664202006363; Mon, 26 Sep 2022 07:20:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664202006; cv=none; d=google.com; s=arc-20160816; b=TN5hmdyyFe3oL3vwzYruh2D54f96pxxu8kWk16NWkYN82fYrZgWwbBXWAIgrPH5PpX zcuBerwAGaZdLnIfwuzVFx+ecocDU+jS0p1WVrKUFk0eJR990Fv3wX+oPs74gwBH2/jW kdF/KqAZTWfEo57jSfjsH4hpzkp3ViHs+IgbUCkatUuOInU1mJakrztsPVep85z/tG07 mrc8WnBWdV42Z7cHDum43wqryHLMv+gyczTkAtYbWjJ9GA2nV7DCSwMp2UKwfy8tSz/o d+N8Cv3V8q+igsUJHXrct3sOI0GfAIzUippTFS86fGD+KbY3nQsIg9Ei7bkWNLfXIN94 x2pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=KkFtIoUdR315WEH9/7niaUp6HiVQkpvQMuCb+rqRTTw=; b=HyJcWw4kCexCwzClV+AhHQy+NaiGZMP/q5q9IQLTuu/kgmYiqA5i43NWRDHpfzGFr2 hOSt+89dN3bPVns7jcYaMUYqHG73Cttr6r3vuMycSA2ZjHu45fa62rffDg4JutvV45MT 1HaJcESIaTNp0bbpVHSFdhoP5QhNhy4QNL18Z9Dv9Kq6ge8l51C7ZFYnhkqbgYWohwKd gbVNnnCOXGZnEL+IyXzLzjRguv69ppskSgHPfVHkSzd/c/BUeT+6cEhGLrtHSeD49SNO g9bVXHvgaypqrzUwspliDnOQWXQ7pUX5R0XZ3Cyh3wq/iMHnj58HwDJdmHfnOx+I8aEC /3Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=LiEuZy9+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z27-20020a1709060adb00b0073de493b83esi18429ejf.147.2022.09.26.07.19.39; Mon, 26 Sep 2022 07:20:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=LiEuZy9+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234110AbiIZN67 (ORCPT + 99 others); Mon, 26 Sep 2022 09:58:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233773AbiIZN6j (ORCPT ); Mon, 26 Sep 2022 09:58:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DA771FD8B2 for ; Mon, 26 Sep 2022 05:12:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 73DD460B55 for ; Mon, 26 Sep 2022 12:02:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C40EC433B5 for ; Mon, 26 Sep 2022 12:02:42 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="LiEuZy9+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1664193759; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KkFtIoUdR315WEH9/7niaUp6HiVQkpvQMuCb+rqRTTw=; b=LiEuZy9+MEEaX3pxgawv57Y1kLtilQQqzNqD8c2vBGk1yVqfyDull4PK2nd/31msm88pMp 5pXCie5Ra7l1HH0TtUGi1Y6RG2qstrDCmPNSCp+ws9nTGZPN2ngxAd/D0jS2DuF+Cb9NxA kAoqNfNkoTX7bGhO3lNeUguDkXgT06A= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 5a640f04 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 26 Sep 2022 12:02:39 +0000 (UTC) Received: by mail-vs1-f50.google.com with SMTP id d187so6290944vsd.6 for ; Mon, 26 Sep 2022 05:02:39 -0700 (PDT) X-Gm-Message-State: ACrzQf1eQL+zPCJtQFIAT86SHg7dbBI3lGgm7f0KEDsYKasRLN480ZS7 Ne/IvJhod+bbnEsUOqFpW0z5hHr6MwIaP6/8utA= X-Received: by 2002:a05:6102:1481:b0:39a:67f5:3096 with SMTP id d1-20020a056102148100b0039a67f53096mr7859616vsv.70.1664193758563; Mon, 26 Sep 2022 05:02:38 -0700 (PDT) MIME-Version: 1.0 References: <20220921185208.3549140-1-Jason@zx2c4.com> <20220921185208.3549140-2-Jason@zx2c4.com> In-Reply-To: From: "Jason A. Donenfeld" Date: Mon, 26 Sep 2022 14:02:27 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] m68k: virt: generate new RNG seed on reboot To: Laurent Vivier Cc: Geert Uytterhoeven , linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Laurent, On Fri, Sep 23, 2022 at 3:10 PM Laurent Vivier wrote: > > Le 23/09/2022 =C3=A0 14:50, Geert Uytterhoeven a =C3=A9crit : > > Hi Jason, > > > > On Fri, Sep 23, 2022 at 2:26 PM Jason A. Donenfeld wr= ote: > >> On Fri, Sep 23, 2022 at 2:23 PM Geert Uytterhoeven wrote: > >>>>>> + if (rng_seed_record && rng_seed_record->size > sizeof(*rng= _seed_record) + 2) { > >>>>>> + u16 len =3D rng_seed_record->size - sizeof(*rng_se= ed_record) - 2; > >>>>>> + get_random_bytes((u8 *)rng_seed_record->data + 2, = len); > >>>>>> + *(u16 *)rng_seed_record->data =3D len; > >>> > >>> Storing the length should use the proper cpu_to_be16 accessor. > >> > >> Okay, I'll do that for v2. > >> > >> (Simply out of curiosity, why? Isn't m68k always big endian and this > >> is arch/ code?) > > > > Yes it is. But virt_parse_bootinfo() below already uses the right > > accessor. > > > > BTW, I guess people thought the same about PowerPC? > > Although I agree the probability of someone creating a little-endian > > m68k clone in an FPGA or SkyWater project and trying to run Linux on > > it quite low ;-) > > > >>>> The way I tested this is by having my initramfs just call > >>>> `reboot(RB_AUTOBOOT);`, and having add_bootloader_randomness() print > >>>> its contents to the console. I checked that it was both present and > >>>> different every time. > >>> > >>> Are you sure the new kernel did receive the same randomness as prepar= ed > >>> by get_random_bytes()? I would expect it to just reboot into qemu, > >>> reload the kernel from disk, and recreate a new bootinfo from scratch= , > >>> including generating a new random seed. > >> > >> Yes I'm sure. Without this patch, the new kernel sees the zeroed state= . > > > > That's interesting. So QEMU preserves the old bootinfo, which is > > AFAIK not guaranteed to be still available (that's why I added > > save_bootinfo()). Perhaps that works because only memory starting > > from a rounded-up value of _end will be used, and you're just lucky? > > I'm wondering what else it preserves. It sure has to reload the > > kernel image, as at least the data section will no longer contain the > > initialization values after a reboot... > > > > Laurent? > > > > In QEMU the loader makes a copy of the kernel and the initrd and this cop= y is restored on a reset. > > I don't think there is a mechanism in QEMU to save the BOOTINFO section, = so I think it works by > luck. I will check. > > Thanks, > Laurent Are you sure about that? Or at least, could you point me to where you think this happens? I'm not as familiar as you with this code base, but I really am not seeing it. So far as I can tell, on reset, the pc and stack are reset to their initial places, after TCG resets the cpu registers to a known state. But the kernel is not reloaded. The same thing that was in memory before is used again. Jason