Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp272587ybz; Tue, 21 Apr 2020 08:46:03 -0700 (PDT) X-Google-Smtp-Source: APiQypKvMBWHeOsx5RIm/EXLkPjqCfgCn8D+WHwtksQIFeRBRRTqeA5SnjN7gn4WV0ydEHX81Mw4 X-Received: by 2002:aa7:c453:: with SMTP id n19mr19315033edr.218.1587483962785; Tue, 21 Apr 2020 08:46:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587483962; cv=none; d=google.com; s=arc-20160816; b=rn17w6CizFcHGJei2YnofthlpgTcBA1ESWXEnnKqeaeoKnljNK1HI46YpEV9MCKc2Y ovBdjxqaTnrBdLOiWBQKpQ5hVegZjGa6S12xuYt1jwJpecn5fbjbbKpkpHrXeelGoxVL NK84Ozun36fvHGsWvGziiOT+u7Sa/diqWjvHFf1/oKcFLUv+Jd1W25bvsiT18hrea7HH 97J9PDLi4D4ejxKvZlk0qFShJrIVEJVea/FL6HH4JG/Gedoo8NtIuu4/f6c/y99nJ14E 0MjkmrTkpkuYZmIWgpW8OUna3DVK32swLgZfroAve0thK8Ysrd++2Zr6f6KyocYz/O0H qD6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SORsRPhtytui9rgjjhHugK9i10g6qzh4zoIcUMIo6qc=; b=X72dwu1gjhfDSfHRJaFOBNqrXUMaPaRcQ9UHFNyh8+AF7sGZg7X0T/5IYV4ftAmmjW ZnHIMaqvPKDA4EiLM9qvmeueeWLTr+uswfHwQVkueclB3QhV1Fdc9gIS8P/OBvf9oQaJ AGMysI5cRQmP983eXbrFqnqnyf91s01KH4AcDfwn/OixFweGakMPL/3OT4BaYUAfixWx QMOAXEaZg2WsSEssGmi/rnGf4P70McZqbSuaUu03epsKisAAxym++cvXYLZRq89UVfLu eycQEMH7WVuDxtFonQBFilonRS3VFSbD+6B7TSwDoNJ73UwFEqt2+bUKIWyTpziYIS1q SAEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="QjI/7kcv"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s25si1718230edw.441.2020.04.21.08.45.39; Tue, 21 Apr 2020 08:46:02 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="QjI/7kcv"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728305AbgDUPmb (ORCPT + 99 others); Tue, 21 Apr 2020 11:42:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725990AbgDUPm0 (ORCPT ); Tue, 21 Apr 2020 11:42:26 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59CD5C0610D6; Tue, 21 Apr 2020 08:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=SORsRPhtytui9rgjjhHugK9i10g6qzh4zoIcUMIo6qc=; b=QjI/7kcvcAV9LVG6XxPF7jyZJV 8Db+cQyihzXdIEIkCylbFuHMaTIxg6nGmhc5HFYNOlaS7JhA2Ml13qy+rtH2A0qmVmuHIhhpxx2zJ VcMatYxNQxeI5PwUEkXvQq5ra1Ze+bp1e5g3cX/+bPnu97kfDJHPDgjjX962YG1H+AHHcEeaxOEK9 I5AGaYTRxAIKKkEnO9D06YxRlRI3g545WCmT1lT5SVxhJvDeUMBA/Xg7u206wjE6aZhsds3YSH1Eo 2cr/qpazPo1FTXbSecXVbT67ofXwRxL1uNQ8gRvO9zWYfntn1ajB27Qw7IUHwgKOak3yYirptk+ww /MYj3enQ==; Received: from [2001:4bb8:191:e12c:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQv2N-0007qr-84; Tue, 21 Apr 2020 15:42:15 +0000 From: Christoph Hellwig To: Andrew Morton , Alexander Viro Cc: Jeremy Kerr , Arnd Bergmann , "Eric W . Biederman" , linuxppc-dev@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/7] binfmt_elf: femove the set_fs in fill_siginfo_note Date: Tue, 21 Apr 2020 17:42:00 +0200 Message-Id: <20200421154204.252921-4-hch@lst.de> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200421154204.252921-1-hch@lst.de> References: <20200421154204.252921-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Eric W. Biederman" The code in binfmt_elf.c is differnt from the rest of the code that processes siginfo, as it sends siginfo from a kernel buffer to a file rather than from kernel memory to userspace buffers. To remove it's use of set_fs the code needs some different siginfo helpers. Add the helper copy_siginfo_to_external to copy from the kernel's internal siginfo layout to a buffer in the siginfo layout that userspace expects. Modify fill_siginfo_note to use copy_siginfo_to_external instead of set_fs and copy_siginfo_to_user. Update compat_binfmt_elf.c to use the previously added copy_siginfo_to_external32 to handle the compat case. Signed-off-by: "Eric W. Biederman" Signed-off-by: Christoph Hellwig --- fs/binfmt_elf.c | 5 +---- fs/compat_binfmt_elf.c | 2 +- include/linux/signal.h | 8 ++++++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 13f25e241ac4..a1f57e20c3cf 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1556,10 +1556,7 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm) static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata, const kernel_siginfo_t *siginfo) { - mm_segment_t old_fs = get_fs(); - set_fs(KERNEL_DS); - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo); - set_fs(old_fs); + copy_siginfo_to_external(csigdata, siginfo); fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata); } diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c index aaad4ca1217e..fa0e24e1b726 100644 --- a/fs/compat_binfmt_elf.c +++ b/fs/compat_binfmt_elf.c @@ -39,7 +39,7 @@ */ #define user_long_t compat_long_t #define user_siginfo_t compat_siginfo_t -#define copy_siginfo_to_user copy_siginfo_to_user32 +#define copy_siginfo_to_external copy_siginfo_to_external32 /* * The machine-dependent core note format types are defined in elfcore-compat.h, diff --git a/include/linux/signal.h b/include/linux/signal.h index 05bacd2ab135..6bb1a3f0258c 100644 --- a/include/linux/signal.h +++ b/include/linux/signal.h @@ -24,6 +24,14 @@ static inline void clear_siginfo(kernel_siginfo_t *info) #define SI_EXPANSION_SIZE (sizeof(struct siginfo) - sizeof(struct kernel_siginfo)) +static inline void copy_siginfo_to_external(siginfo_t *to, + const kernel_siginfo_t *from) +{ + memcpy(to, from, sizeof(*from)); + memset(((char *)to) + sizeof(struct kernel_siginfo), 0, + SI_EXPANSION_SIZE); +} + int copy_siginfo_to_user(siginfo_t __user *to, const kernel_siginfo_t *from); int copy_siginfo_from_user(kernel_siginfo_t *to, const siginfo_t __user *from); -- 2.26.1