Received: by 10.223.185.116 with SMTP id b49csp6374896wrg; Wed, 28 Feb 2018 08:22:40 -0800 (PST) X-Google-Smtp-Source: AH8x224w95YrcnpHMnoXpz/bRLwdc8Tw1JxTwLeDA84+XERjMNhKq5UvPQBBxC+EE1agyF3mBWTQ X-Received: by 10.99.176.68 with SMTP id z4mr14311212pgo.74.1519834959964; Wed, 28 Feb 2018 08:22:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519834959; cv=none; d=google.com; s=arc-20160816; b=V5TQ2a5lGeUX7PSiF2fmrg4W7RaCK69depAME6f7VfKoHdtLfNdh/6TIaLkdiSE7wO hfD/zAK5EX48fRnrnfWlx2sl4EETwkollIcoKWP0R0LfDQWWC4KNKP5HIZ+HZYjnHHJp q/MCXg+cr97PtT6DtWZPNaoOW63/KTjYA8pjQPPvfQjXmFtUaqNno0ETJPNBChCRaeXZ ndW4Bnq5WY6wcaerCFBjXBHpLqICRq2wSCK7CjEYIcaLd/lSRPotGG8kB3+SBTpeZFKP Mj5KBmh4RPqb6mP5/aBjMJiiUe8fbYxa9eBSofwt/5QA6H+H1VAap1eh5zIGu4UkYg4l ny6g== 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:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=Isj0k/CRHlZ66CPsFXhqE6TFvEb34CYlaNtxrs3JEq0=; b=S9R09j4fl+Q56GHwMroMLitJ2+5O+SB5Q5KY0bFws5Ca6RVstwVZxmZHWhEpQeHqHG 9dcMbW3+9sv6y8DXVN9rO7O0a85wqWuCy/evsYx65W48Q251KMyiX7c2Qxbjv+hbqxQZ tvoIPyyPJRKI8xST54CzsIaYT9SRfyeTd2Lk5h/q/cc4g6/CjrfUfhprsdrMQlEJc2cR 2nk3CvoDGt5UEKjYuLOLx0ed3zrH/R5mjWxBaent3Kr6WH4RuTPaKo75Eo4YwBmKTTZz FePvN6eyfG/4e99PeJrqdwPKYoqJJfFKuHbChksymj/UC4wR0iZoGHY5y5dmiy5z+oIt 4Nlw== 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 r39-v6si1497123pld.53.2018.02.28.08.22.25; Wed, 28 Feb 2018 08:22:39 -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 S935273AbeB1QVD (ORCPT + 99 others); Wed, 28 Feb 2018 11:21:03 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35410 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935261AbeB1QVA (ORCPT ); Wed, 28 Feb 2018 11:21:00 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yp-0006XP-OX; Wed, 28 Feb 2018 15:22:28 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yj-0000GE-Rg; Wed, 28 Feb 2018 15:22:21 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Thomas Gleixner" , peterz@infradead.org, "Li Jinyue" , dvhart@infradead.org Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 204/254] futex: Prevent overflow by strengthen input validation In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Li Jinyue commit fbe0e839d1e22d88810f3ee3e2f1479be4c0aa4a upstream. UBSAN reports signed integer overflow in kernel/futex.c: UBSAN: Undefined behaviour in kernel/futex.c:2041:18 signed integer overflow: 0 - -2147483648 cannot be represented in type 'int' Add a sanity check to catch negative values of nr_wake and nr_requeue. Signed-off-by: Li Jinyue Signed-off-by: Thomas Gleixner Cc: peterz@infradead.org Cc: dvhart@infradead.org Link: https://lkml.kernel.org/r/1513242294-31786-1-git-send-email-lijinyue@huawei.com [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- kernel/futex.c | 3 +++ 1 file changed, 3 insertions(+) --- a/kernel/futex.c +++ b/kernel/futex.c @@ -1531,6 +1531,9 @@ static int futex_requeue(u32 __user *uad struct futex_hash_bucket *hb1, *hb2; struct futex_q *this, *next; + if (nr_wake < 0 || nr_requeue < 0) + return -EINVAL; + if (requeue_pi) { /* * Requeue PI only works on two distinct uaddrs. This