From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 3C5373CC338 for ; Tue, 12 May 2026 16:16:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778602616; cv=none; b=BimqgPCcKSWjVefI+Ye2vvckgQbdtZs6eTgz7q7EHRXfVTuA+bKIKumEedFz/ldfrAS5uJr55OLwPLdGC/hbLg6KXMQoecmrupI5Z/mEDHSUIHd5qjB/wwQ5hvsGHZ6+AOsNnWkBMjuI62o8S6rx5amG77TB4Lx8BtIgO4SFzjA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778602616; c=relaxed/simple; bh=b/kTdcdowZSGwWukdFlz0EEIsuDZ7AWOQxy89lVAfKk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=G9xIN7Mt0EANovVk+vElDUIT6BuGlFwxp4c+fis78xFxZ+ABuP+QAHuMTDe7tDkSXVniGkk8ira/jzntDHJNusDPHlCRATgEs2hcjEgoRpf9Iicrvc+/aUCqQCdIk5RkKaFTk2A3RAjwmtv+Jl9nnDe3T1t5KdP+xPqOFWR9xdM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Q1hTcab0; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=McJFpDZB; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q1hTcab0"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="McJFpDZB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778602608; 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=RdIDafiAsEotTrCTT3hzJY/6W/WUXSIEIyZWVk3Oh7Q=; b=Q1hTcab0CYy9cHaAKhmJlMJbVO12D0AahsL5k9/eLJqByqXrOvlXcO4O+JKOXrdSPIB8My 5cc2DKwb8SwJF6gYid09DlvnUxUVETVIi5rHq2TYXprCSLX58oGCSdqeO2Qo2EQ+/Jov2B dsxAfWHAS/JyW8uQkFrIn4vT0PZZR0Q= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-510-UVti7KhgMOmwa6Nhw2BBww-1; Tue, 12 May 2026 12:16:47 -0400 X-MC-Unique: UVti7KhgMOmwa6Nhw2BBww-1 X-Mimecast-MFC-AGG-ID: UVti7KhgMOmwa6Nhw2BBww_1778602606 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-45b7ff2140eso619295f8f.3 for ; Tue, 12 May 2026 09:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778602606; x=1779207406; darn=vger.kernel.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=RdIDafiAsEotTrCTT3hzJY/6W/WUXSIEIyZWVk3Oh7Q=; b=McJFpDZBiPG0cyx43EKG/tUPddmnHbAdEcGVJW/t91N1Dw1V25ySUFH+rYQ4ImSo8L qgNOv+yGypNhq+Zpe17rDB56KQf2DZje3WacCcDaB538jx+t7IaEHrc7PpLNYTCHihle gI6a8oFis4bIO2jyCVlMhvfdS0M3kgRb4UuhHJa3DSaUsR6791cBb9ntZYKnEJnVNf6Q QtmNZVqhzUVxFqt4kGa3w8x6vyRCLUEkCpR97HcFKwFgZ1psrDVj+dz62ghQYSbGHaGM PfaTVIl8jexE4+s9WwBxj0o95kXJiD3P4+ihhsU2Ns8osixQOcsh1LQViS1xqsa5pAbi F9xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778602606; x=1779207406; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RdIDafiAsEotTrCTT3hzJY/6W/WUXSIEIyZWVk3Oh7Q=; b=H9pxDAugLkaq4fbB8aSAT2hpmQaH0OupcWeoJEpFQrrx20xbWgYq/lfr5oRChYZhaZ TebLd17nHqxHOcd2yyWv8geW8louFLdpQ2e0KFrjeflJj8t18wtj2E+ACUJf0MlBKxjL JWkBwTp2o0AkI2cM0wn3X8ztAU7PxDS5n1q33aTG5o6K0Rqz8dVSgYQ3vRyEyCcaY20k vQvtPsa9tLduZX4l8LWFTxIlkadShWs6wa2UH9cFEGeb1ltARzAsFyxHFfd8cvp18NRc Ki+QeRR9CCsfXFSsNQ/XszGGQNXu+ashhILkfAmcSy5wHjz4hbRchqZIQf3QMq1RruDu p4Hw== X-Gm-Message-State: AOJu0Yy8BLYGte9WMCnn4ALSsF8e6pAnuQnncMP4JuIWN9tERyczzXd4 rCAjYs4hQHDE+hSmR1LICzBuvgqHa1khEkLUU1vPN9bAPrxhmkM9ws/DHFbeKeeOHD5rbaawD9w PSlspukja58KgqTvHQB/F+7XyxdBTNsjPz6kiFg5RsIAYHZidGAMQWvSUy4k9npjqbA== X-Gm-Gg: Acq92OETA474wiQMJKgqoeMR9YyBWcKY7ThXcjJ1mxucsG5FPxJeE2pLmu+aqk/095F B7o0f6zDt7dpZN8P6djKTtWAzFI4DY/p7Cti2AgaUkfygPdmRg9Kj3frQb2MOUxIt1ndDUJC6bt tMGk5eye66u24AefYyJQJvmjjwMT+LP4pjgEemTOYvSYtjiSrEvnMZQYE1unZCOGOnc2JdKJ3t0 4NnbliLFHUcHVwAHIKUW8E7DXr+gGHLBkHoimutDH9oPTF7zr6YwBR4THGFPvXgm7qQjG5F2Osr uY+fhgHN/tLTGy7Rzgp7FvQN9O1fTArhnK2d4cqhaDp36V4L5LNYVWghFqCyCwRcG8CQBKWnj6r 6Ew8GYJW2Om9V2UUZTB/XBrHJ2n3aEIPUF9cCSM/3OVwFN5bGUYNoALdmdH2f5JggjjZOpKq9MZ 1dJB4ASTw= X-Received: by 2002:a05:6000:4027:b0:455:7c9f:a49e with SMTP id ffacd0b85a97d-4557c9fa4c8mr25988063f8f.25.1778602605765; Tue, 12 May 2026 09:16:45 -0700 (PDT) X-Received: by 2002:a05:6000:4027:b0:455:7c9f:a49e with SMTP id ffacd0b85a97d-4557c9fa4c8mr25988022f8f.25.1778602605341; Tue, 12 May 2026 09:16:45 -0700 (PDT) Received: from vschneid-thinkpadt14sgen2i.remote.csb (213-44-135-146.abo.bbox.fr. [213.44.135.146]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4549120eb95sm32837293f8f.20.2026.05.12.09.16.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 09:16:44 -0700 (PDT) From: Valentin Schneider To: Ruidong Tian , mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, kprateek.nayak@amd.com Cc: linux-kernel@vger.kernel.org, oliver.yang@linux.alibaba.com, Ruidong Tian Subject: Re: [PATCH v2] sched: move stack_canary to the start of the randomizable region In-Reply-To: <20260509035014.2220372-1-tianruidong@linux.alibaba.com> References: <20260509035014.2220372-1-tianruidong@linux.alibaba.com> Date: Tue, 12 May 2026 18:16:43 +0200 Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On 09/05/26 11:50, Ruidong Tian wrote: > task_struct keeps growing over time. On architectures that compute the > per-task stack canary offset from asm-offsets.h and pass it to the > compiler via -mstack-protector-guard-offset=, this growth eventually > pushes stack_canary beyond what the target ISA can encode. > > On RISC-V, canary loads are emitted as > > ld t0, TSK_STACK_CANARY(tp) > > where TSK_STACK_CANARY must fit into a 12-bit signed immediate, i.e. > [-2048, 2047]. Once stack_canary sits past byte 2047 of task_struct, > the build fails with > > cc1: error: '' is not a valid offset in > '-mstack-protector-guard-offset=' > > * On RISC-V, CONFIG_STACKPROTECTOR_PER_TASK depends on !RANDSTRUCT, > so randomized_struct_fields_start/end always expand to nothing and > stack_canary lands at a small, stable offset well within the > 12-bit signed immediate range. The build error goes away. > > * On architectures that enable RANDSTRUCT for hardening, stack_canary > stays inside the randomized region and is still shuffled together > with the other fields by the layout randomization, so its hardening > coverage is preserved. asm-offsets-based architectures read the > shuffled offset at build time, so the generated canary accesses > remain correct. > > pahole on a typical 64-bit config shows that the area around the > wakee_* fields already contains a usable hole: > > struct __call_single_node wake_entry; /* 56 16 */ > /* --- cacheline 1 boundary (64 bytes) --- */ > unsigned int wakee_flips; /* 72 4 */ > /* XXX 4 bytes hole, try to pack */ > unsigned long int wakee_flip_decay_ts; /* 80 8 */ > struct task_struct * last_wakee; /* 88 8 */ > > Move wakee_flips to sit after last_wakee. That opens up a clean > 8-byte slot at offset 72 into which stack_canary fits exactly: > > struct __call_single_node wake_entry; /* 56 16 */ > /* --- cacheline 1 boundary (64 bytes) --- */ > unsigned long stack_canary; /* 72 8 */ > unsigned long int wakee_flip_decay_ts; /* 80 8 */ > struct task_struct * last_wakee; /* 88 8 */ > unsigned int wakee_flips; /* 96 4 */ > > Suggested-by: K Prateek Nayak > Signed-off-by: Ruidong Tian Reviewed-by: Valentin Schneider