Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp485728pxa; Fri, 31 Jul 2020 18:29:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwozp9evsDgLHI5NiHJnciOiVnuzieZz525PKAX65RQffOqBwJS1jH7WlFWkOr+7fEuZi8R X-Received: by 2002:a17:906:9984:: with SMTP id af4mr7157014ejc.90.1596245357442; Fri, 31 Jul 2020 18:29:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596245357; cv=none; d=google.com; s=arc-20160816; b=Fyj1UeYJqANBws1+eVFv4GoOntPEe7BDgmUIV50IQg0pBHyames2pXD6TqNZvGj0oh 4ocqrp3ntr9ZRToYzgyvrCyeGXFMOcM1pbDtSOFi7X+DTdLZY2FUIPioXpwKlcqV51xL mbhcq+aL6Cygl6H61kbevJVX2NUPQciiZ0LU16sU9L67LqX+nYWtcKXpP6HVVTw0ZNRm WvvjQO6sdP4AMdOtdetI0Xi+4ObIq/W8tdR87HZZ9p9j/g7GpE+U88Xiwyb/bD53tVTD 70AOu99qbASjDFLT7Qmdz/uV2AG+HZvVDbfX3XPONNhipY0gjvdgyoYnmjyxZKQB8LTB VQVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=R7S9crGkSS+zqKV+6akgjVw/AncewqiAu9qufG43ZRg=; b=vW950ixAWp0an1KJcwwYs/DclbmyEFMTnindoaJeVgGk3Iv3iesPb8HNtF7QNPvXnm 8/ZPwZrJzbfQeSS06ly1H9b2O+J1qao8jA2AwV0ubrrzNFbN4W8X/MMh8mjpE4PGkJCK b7S9Nj47PVeGtvwmK6rx7S3ya6tZDoggISGn7LYfI1Q66nnCkrL8QrKOMnD1BOvjXegI gYe2pGCA00l1MSdZftBr8OKVsaMKs8TRZjWyHqudFiwulz4ohrpPdm2vVMqjmFeAvS3g Uw28Ec4PvqXyPEe4B9X0oZp2R5SGf/aeWoCs9ptExsfrcnoDI1lIS+eHYLws0CQVd+3d 0B/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MGWdNGvG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h12si1410251ejx.85.2020.07.31.18.28.55; Fri, 31 Jul 2020 18:29:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MGWdNGvG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727994AbgHAB2K (ORCPT + 99 others); Fri, 31 Jul 2020 21:28:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727095AbgHAB2J (ORCPT ); Fri, 31 Jul 2020 21:28:09 -0400 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C20A8C06174A for ; Fri, 31 Jul 2020 18:28:09 -0700 (PDT) Received: by mail-qt1-x843.google.com with SMTP id s23so24429671qtq.12 for ; Fri, 31 Jul 2020 18:28:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=R7S9crGkSS+zqKV+6akgjVw/AncewqiAu9qufG43ZRg=; b=MGWdNGvG/aOp4sfcJNv9ej1bqPcyavBaerB+JRyI7t8uLrCovVqmRKcPD1uuesEusk 0j9Wt+msOoIvdm+dldTktOMUtsoXcShCNG5wp+MuOynQPyVqRxWu1ylr0X65BnRUQxDZ TDvNAjWeAuF2K3ewYReTC1YgwUXRqZXuMKotqLSja/lQePnureOJtpItKp4KOF52f2R+ 46EU23VbTQWiRZL+CBCOA89oZRlwoPWkIBjs22I9NzI/6dRX+ugZBjscqdF29ftmz1rF td4N2M2Vn+bNwNwzCHEjGkmu1RaPZtTUjwUUU7HxZ7qeOvdM1zVg1nCejSXouGJAWQo8 7DBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=R7S9crGkSS+zqKV+6akgjVw/AncewqiAu9qufG43ZRg=; b=TP76Kc8LLs9E+rPGPZDypBlqggkD2FVtV9A5AIULj7vfm3TeRsxkuEiy/x40QLvh1i 5i14+QdSa1GtauOpjKGW42vJ6KojdgAb21KVwRUnU1V1XyiNHzyxhkDcXwpkvBG+a4U2 +HD+TIVDEf0Qr87vMYuM7feyYn5b3Lef4g6Ingb9xy9/deYcTJ0iiuyGHnPgX/ehwDV8 xtj6oJsTysdKNNh2dmWMN50ZoQNE3tdNC6Gc7c1cZy3T9TYQj+cFR9rDNHxVe2q2rkp+ eGdurhAAiAhvR2dmhyec5lZeE1AVnTC5EPLxl5bvq3dOErEjZMuwpgifU4ZH/Bu8bUfi G4SQ== X-Gm-Message-State: AOAM5339HbkpRukgTQAW29L/v3ZVZLRCSQhcloQkcft7gpkPl4FvOP6q uTO1ZeQzlAihldj7RGHDV6oZSd0= X-Received: by 2002:ac8:65cd:: with SMTP id t13mr6681148qto.368.1596245288751; Fri, 31 Jul 2020 18:28:08 -0700 (PDT) Received: from PWN (146-115-88-66.s3894.c3-0.sbo-ubr1.sbo.ma.cable.rcncustomer.com. [146.115.88.66]) by smtp.gmail.com with ESMTPSA id r6sm8484023qkc.43.2020.07.31.18.28.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 18:28:08 -0700 (PDT) Date: Fri, 31 Jul 2020 21:28:04 -0400 From: Peilin Ye To: "Dmitry V. Levin" Cc: Elvira Khabirova , Oleg Nesterov , Dan Carpenter , Arnd Bergmann , Greg Kroah-Hartman , linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: Re: [Linux-kernel-mentees] [PATCH] ptrace: Prevent kernel-infoleak in ptrace_get_syscall_info() Message-ID: <20200801012804.GA220239@PWN> References: <20200727213644.328662-1-yepeilin.cs@gmail.com> <20200801002142.GA27762@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200801002142.GA27762@altlinux.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 01, 2020 at 03:21:42AM +0300, Dmitry V. Levin wrote: > On Mon, Jul 27, 2020 at 05:36:44PM -0400, Peilin Ye wrote: > > ptrace_get_syscall_info() is copying uninitialized stack memory to > > userspace due to the compiler not initializing holes in statically > > allocated structures. Fix it by initializing `info` with memset(). > > > > Cc: stable@vger.kernel.org > > Fixes: 201766a20e30 ("ptrace: add PTRACE_GET_SYSCALL_INFO request") > > Suggested-by: Dan Carpenter > > Signed-off-by: Peilin Ye > > --- > > kernel/ptrace.c | 14 ++++++++------ > > 1 file changed, 8 insertions(+), 6 deletions(-) > > > > diff --git a/kernel/ptrace.c b/kernel/ptrace.c > > index 43d6179508d6..e48d05b765b5 100644 > > --- a/kernel/ptrace.c > > +++ b/kernel/ptrace.c > > @@ -960,15 +960,17 @@ ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size, > > void __user *datavp) > > { > > struct pt_regs *regs = task_pt_regs(child); > > - struct ptrace_syscall_info info = { > > - .op = PTRACE_SYSCALL_INFO_NONE, > > - .arch = syscall_get_arch(child), > > - .instruction_pointer = instruction_pointer(regs), > > - .stack_pointer = user_stack_pointer(regs), > > - }; > > + struct ptrace_syscall_info info; > > unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry); > > unsigned long write_size; > > > > + memset(&info, 0, sizeof(info)); > > + > > + info.op = PTRACE_SYSCALL_INFO_NONE; > > + info.arch = syscall_get_arch(child); > > + info.instruction_pointer = instruction_pointer(regs); > > + info.stack_pointer = user_stack_pointer(regs); > > + > > No, please don't do it this way. If there is a hole in the structure that > the compiler is unable to initialize properly (and there is a 3-byte hole > in the beginning indeed), please plug the hole by turning it into > something that the compiler is capable of initializing. I see. I will do that and send a v2. > Also, please do not forget to Cc authors of the commit you are fixing. Sorry, I forgot about that. Thank you for pointing it out! Peilin Ye