Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3275444ybz; Mon, 27 Apr 2020 13:09:30 -0700 (PDT) X-Google-Smtp-Source: APiQypKJVl6ddMk9/xglToHXvZlXKPyktIlKROyyIpUdki0w2clD2z2dWg+8W4q4x/ei0S/rSD+g X-Received: by 2002:a17:907:9489:: with SMTP id dm9mr908775ejc.9.1588018170086; Mon, 27 Apr 2020 13:09:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588018170; cv=none; d=google.com; s=arc-20160816; b=KyxvHDrTjQ/gVnMMNddl9+d+0vVW/fXU4WGWxDdo2lUeCZyWAVawqNACOfXMO+ItWU xvQt1V1hjSNtXBblvVTV/LAp/JRa9L/At8Jh7dOdZwYHFbCI9U8rCoxfvDL6p4j3ub6C mKH0d15GWo0Lk3Al+GsM+jt4yYPQo+Caf3oFnJ1VV7ztp1BAfAVTelwVzoTTCiVbISeV sdKiKfHErRk3H2i64ALF3injABHBXc8RFs1VoPB6xZ81epGzTyhPG7g+aRsRsbj1eWCI jzLOPGqmQUBj7jGg+/wWzwsYW2z40dQLE5N7AD7ZkMbeSNQ7YG50i1gi7HBaaLBfOIVN 5dJw== 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=tRh2egFE5bL+lOO5QZcFzobBLROoVTEyjp5GB1YlRSI=; b=DMkm62q0uno5JF8v9b4IIR8r/jNsa9Ms8WWGaPOrLK0u9MrBliY4g1yAzXxsKYir/N inEF+3GB/BGL7vKfkOE7gOj+PTahe8Rl13jw6k/ZCESLWizgq4j0upsUa4hy/ObEEZXN mlbDuiWZ6LUmeq2oUHvDeOz0qYbarE/aaCWWLBTjlQB4JVM37GW5ptni9RD+KAI519fs 1R78WsH9BzxcfWJt3dWghZ8zg8rVHIpJtdq2n20WItkOswNlYyfENF0hwM7rsMrxAp8C dc4hGMPlbYjBFgukkJ1cngSfEnuOVpVt4eydsS9mawhCFtHSU+u6YM35jBKlxyfN1k2G hyzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=B4917ULy; 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 bt18si348220edb.139.2020.04.27.13.09.07; Mon, 27 Apr 2020 13:09:30 -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=B4917ULy; 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 S1726486AbgD0UG7 (ORCPT + 99 others); Mon, 27 Apr 2020 16:06:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725919AbgD0UGs (ORCPT ); Mon, 27 Apr 2020 16:06:48 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5482EC0610D5; Mon, 27 Apr 2020 13:06:48 -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=tRh2egFE5bL+lOO5QZcFzobBLROoVTEyjp5GB1YlRSI=; b=B4917ULyuyzDL/PEWb5k2c845z OgAxxZzldO+FXYvaMWPFOyGIUHo8cXALBoKkBANOp7XIBAwXpMpNKM3j6xb1xqSyp9+m6yK/8FWnc 37Myv1SWyyKMbTUkFz89+OIMrl4cm4xNayxW6RyzX8VMU8relvPuDfiSqWXTIq1HnkoGoXTgPk2Y0 l//xBrLBYmdoczVvQxLsGfD4a84xKVhvHJCbHdaZBOxC2tG8ilUrTH9esfyLfarZpWZ1JDR1Zoz0c pM7U2MY08y9CDb70vyjdwMs6j3SpSI5MLaEyUID//Wf2HuMJlbhp8uB8618d4ilXVG5Cz+O5SDCLI /HZ2tx/A==; Received: from [2001:4bb8:193:f203:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTA1T-000189-Ol; Mon, 27 Apr 2020 20:06:36 +0000 From: Christoph Hellwig To: Andrew Morton , Alexander Viro Cc: Linus Torvalds , 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/5] binfmt_elf: remove the set_fs in fill_siginfo_note Date: Mon, 27 Apr 2020 22:06:23 +0200 Message-Id: <20200427200626.1622060-4-hch@lst.de> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200427200626.1622060-1-hch@lst.de> References: <20200427200626.1622060-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 13f25e241ac46..a1f57e20c3cf2 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 aaad4ca1217ef..fa0e24e1b7267 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 05bacd2ab1350..6bb1a3f0258c2 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