Received: by 10.223.176.5 with SMTP id f5csp3388318wra; Mon, 29 Jan 2018 12:28:18 -0800 (PST) X-Google-Smtp-Source: AH8x226e41Wn8sPihfIbQwQ6Hj5py1XPqI/WKJrwatbaWOA3nDNQ/+YlRcZpKtN65XbG/Dqouur3 X-Received: by 10.99.144.76 with SMTP id a73mr22033639pge.376.1517257698826; Mon, 29 Jan 2018 12:28:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517257698; cv=none; d=google.com; s=arc-20160816; b=x6o2oLjWJUUknJopuOoga0lmq+KOWQMfKKrFLDFwVqUzRV69eIPGIrFshj7Czi5n+X /eLE21HWL9ZGZbtz7eK+xbSeYvIPxClMcibdxHI4jkoOQH9LWTAfEQcyV3PZ1kFUjihz xVb8rR/DBvdZAno8BlPCVfDtyxWRkAWiY8wgtrxnDip3S0ybZxrdlfLvhLvNAuVHMJfY SG1hlUX8hPjJ8BefEogm68RxBc8prmDurouGg97JJlw4+P7zBKxYV28klzPR5duu8iyL MYJniPpoTXCPX9h4nuKB9EfhscrnMmgIUWng3eBPX8b/4oh/YY60raDUGN4QrCL605zT kNNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=1QGDRTBkZvRRsFoYvnh8QKoKXpJWPaK4p2hFHRRNKW8=; b=Y0kollqSM/oiM2fEC7zODU9mgb+//JC0R/DNVyFZFtlWs2xJT5izDh8m+eQL2zd5XQ XOFOWOar/cJFCF7UqoWGzAH4SBq/Kb5HggnvlE9pI2rEDB8VBXcU8k3zxF06dEQYLBw8 b4orTvRkVhGcdHzLe59AeENxG7GaCCmGqMxlo10eSZ84gDoagmy5KBakiWBDsWUvAhDy mqnVZFoKQ84/OFyS1UWfmUC27ItzwdvfANj7lHSU/xuEbF0ZEpU2+MfyQsHHDLl+iadL vUTMnDMidbg6lEYqI4nQkC2+SWngozs99q05XcIziGceCNkvDnvhwNpGhhog2onhQDJb 7BKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 90si244425pfs.287.2018.01.29.12.28.04; Mon, 29 Jan 2018 12:28:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754835AbeA2U0v (ORCPT + 99 others); Mon, 29 Jan 2018 15:26:51 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:44484 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754517AbeA2UQ1 (ORCPT ); Mon, 29 Jan 2018 15:16:27 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 06D342EAA; Mon, 29 Jan 2018 12:59:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby , Jeff Layton , "J. Bruce Fields" , Alexander Viro , linux-fsdevel@vger.kernel.org, Jeff Layton Subject: [PATCH 3.18 34/52] fs/fcntl: f_setown, avoid undefined behaviour Date: Mon, 29 Jan 2018 13:56:52 +0100 Message-Id: <20180129123629.677671722@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123628.168904217@linuxfoundation.org> References: <20180129123628.168904217@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiri Slaby commit fc3dc67471461c0efcb1ed22fb7595121d65fad9 upstream. fcntl(0, F_SETOWN, 0x80000000) triggers: UBSAN: Undefined behaviour in fs/fcntl.c:118:7 negation of -2147483648 cannot be represented in type 'int': CPU: 1 PID: 18261 Comm: syz-executor Not tainted 4.8.1-0-syzkaller #1 ... Call Trace: ... [] ? f_setown+0x1d8/0x200 [] ? SyS_fcntl+0x999/0xf30 [] ? entry_SYSCALL_64_fastpath+0x23/0xc1 Fix that by checking the arg parameter properly (against INT_MAX) before "who = -who". And return immediatelly with -EINVAL in case it is wrong. Note that according to POSIX we can return EINVAL: http://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html [EINVAL] The cmd argument is F_SETOWN and the value of the argument is not valid as a process or process group identifier. [v2] returns an error, v1 used to fail silently [v3] implement proper check for the bad value INT_MIN Signed-off-by: Jiri Slaby Cc: Jeff Layton Cc: "J. Bruce Fields" Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Signed-off-by: Jeff Layton Signed-off-by: Greg Kroah-Hartman --- fs/fcntl.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -113,6 +113,10 @@ void f_setown(struct file *filp, unsigne int who = arg; type = PIDTYPE_PID; if (who < 0) { + /* avoid overflow below */ + if (who == INT_MIN) + return; + type = PIDTYPE_PGID; who = -who; }