Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2241412imm; Thu, 7 Jun 2018 07:34:33 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKBciEZ5GHNMcFxv1MMDFakcRyzp5i1RpSNbFwme0nDv65qQ5KzYhNLcS9RMtuZtd5xgE/a X-Received: by 2002:a17:902:bd42:: with SMTP id b2-v6mr2324943plx.23.1528382073930; Thu, 07 Jun 2018 07:34:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528382073; cv=none; d=google.com; s=arc-20160816; b=Cz0tfdF7LLdOyPz/lCTM+5Rj/PSS0Tzp3UJ4LabqWf0heymcE2QJ398W+04Xcc304U QjHi8QC9sDU3fFncFYaQqZyk9avb3rvCBn0yGJe5c8E9miDs11y4po/nDaijpDQMPD61 MEFNPUjgt4xz703bh1lRPSUCNUlwkNt0+q2/nphoOxAJVRfvHkao3jGnw0bTFoWG5upR EAJ74RxfyFZ3zg1TDj7zyaHwWphZx5q/hsp8SIE8dE6F1lQtNL2TG9d0intnRwCIpgKI gJnIYnXdW/COXp7LneSrkzWQNRyDQkITWSV27mET/hHHv+zP8l5v3WwoV1neE/qHqmUP AYDA== 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=ZvrW5ryTF6R5dKL0Bv72GyGVd4J9ZtxkfydRguL4JIk=; b=qCOCBJJS9EWINf6lJHoPrTPdgM3GYJ8FKBCk1xpkJIQwfkCQKxpxeJPJzLbshOl3Jz VLZtAMjH5AYZsYwTIJwkY/aCOPgupPwVoOo6KxHvswHbQa9dG9Aq4c67yJ0fkZCVM5gz AZoMw0QKKFJL+BIZqCwwnEcYytA1noSxRiMnbEMTkSFumQ0fST0z37x4oglS6rLnSh9Z yZvV1pKqiBCmG6PjiMG8wgWgkt7W2TNn8EVcEv/Bc7r2DInl298RnO4OE3A5+EU/Ir3V 5np3jd6BLF7OKIopq+GaluOwyOz4wQQWOBNZwXYUTEzILRCrHlpa+9FiRRXp+d6r+Jjn Cx4Q== 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 b2-v6si10029208pgt.611.2018.06.07.07.34.19; Thu, 07 Jun 2018 07:34:33 -0700 (PDT) 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 S933897AbeFGOdJ (ORCPT + 99 others); Thu, 7 Jun 2018 10:33:09 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40308 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933880AbeFGOdF (ORCPT ); Thu, 7 Jun 2018 10:33:05 -0400 Received: from [148.252.241.226] (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 1fQvbg-0005Zn-Go; Thu, 07 Jun 2018 15:09:40 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb6-000315-CU; Thu, 07 Jun 2018 15:09:04 +0100 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, "Randy Dunlap" , "Michael Kerrisk" , "Jens Axboe" , "Mikulas Patocka" , "Joe Lawrence" , "Al Viro" , "Josh Poimboeuf" , "Linus Torvalds" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 209/410] sysctl: check for UINT_MAX before unsigned int min/max In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 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.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Joe Lawrence commit fb910c42ccebf853c29296185c45c11164a56098 upstream. Mikulas noticed in the existing do_proc_douintvec_minmax_conv() and do_proc_dopipe_max_size_conv() introduced in this patchset, that they inconsistently handle overflow and min/max range inputs: For example: 0 ... param->min - 1 ---> ERANGE param->min ... param->max ---> the value is accepted param->max + 1 ... 0x100000000L + param->min - 1 ---> ERANGE 0x100000000L + param->min ... 0x100000000L + param->max ---> EINVAL 0x100000000L + param->max + 1, 0x200000000L + param->min - 1 ---> ERANGE 0x200000000L + param->min ... 0x200000000L + param->max ---> EINVAL 0x200000000L + param->max + 1, 0x300000000L + param->min - 1 ---> ERANGE In do_proc_do*() routines which store values into unsigned int variables (4 bytes wide for 64-bit builds), first validate that the input unsigned long value (8 bytes wide for 64-bit builds) will fit inside the smaller unsigned int variable. Then check that the unsigned int value falls inside the specified parameter min, max range. Otherwise the unsigned long -> unsigned int conversion drops leading bits from the input value, leading to the inconsistent pattern Mikulas documented above. Link: http://lkml.kernel.org/r/1507658689-11669-5-git-send-email-joe.lawrence@redhat.com Signed-off-by: Joe Lawrence Reported-by: Mikulas Patocka Reviewed-by: Mikulas Patocka Cc: Al Viro Cc: Jens Axboe Cc: Michael Kerrisk Cc: Randy Dunlap Cc: Josh Poimboeuf Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds [bwh: Backported to 3.16: - Drop changes in do_proc_douintvec_minmax_conv() - Adjust context] Signed-off-by: Ben Hutchings --- --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2233,17 +2233,18 @@ static int do_proc_dopipe_max_size_conv( struct do_proc_dopipe_max_size_conv_param *param = data; if (write) { - unsigned int val = round_pipe_size(*lvalp); + unsigned int val; + if (*lvalp > UINT_MAX) + return -EINVAL; + + val = round_pipe_size(*lvalp); if (*negp || val == 0) return -EINVAL; if (param->min && *param->min > val) return -ERANGE; - if (*lvalp > UINT_MAX) - return -EINVAL; - *valp = val; } else { unsigned int val = *valp;