Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp889506imu; Thu, 13 Dec 2018 06:12:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/W5ZIm2xAbuyTcU+j16hegB0MCbdFwPkqzeyAXPQ21Sl8qM6VHlXJsQxmyRdGHR8eL0tFGM X-Received: by 2002:a17:902:4681:: with SMTP id p1mr24487818pld.184.1544710332863; Thu, 13 Dec 2018 06:12:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544710332; cv=none; d=google.com; s=arc-20160816; b=bWovAJhzs7Kg9GKe7sdafwvhzXdkBalLwWJsQRv9NfiRa4tEFoOExWLGpSsuN/FbWl oYJWJFeKA4y6IyeR7yc+B6f8lit1xiiVQe01AOQ2XTxoYGVV7NVWaeOXZICEa9UOqdFy W53NlzLtODddfSIcsB7P0jOWLzIQfu2aOpY9M40GkS6EJ/Urk1DmCHxeady1UApthEjB pTXBNJzUAdC6atNHXUBoz+SlWS/UXiFyxVuj23ETUZKWYLoFKLLPY2j6Bj5HeGiV2zmP 8EholM0HxR5JWt09wCeRFFHVZ79Ym5vHi0QRnVw8GiMHdbJ7lWW81Rt224UF/ABd87Pe W3PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=oumH74TF10yy9dfFHYAaHwVfujF7GOhL7w5e6u4dIEQ=; b=psJlhPsixxsb8Lo37/EGoL3bMVQ+NQk6qPehHLzaXKAn+K+Tn1HS9Xoufv65eE+Xl1 C9XpYbHjkFUO9YxkUqW8bdLdVL2jkwX899torJ/YKgiTRLoSXbHV6aZ3H13gk8Wm4QHn H0B0qr4/YWpNdYIPdHczNJEN1fXS4dSd/RHXo7CVGB+sbgvfPotkDLLwENG1k33JjRdK f+6mWGjjfh4gdZOPc7W5Zo8qjzQs6YunxY3d+xkANPheACGmC3oiUO38xn29Z5SS+fsV YVoAWx6kLjYqsFjoZ7ssDywWaPhb79i5kqvJvpopw2MOXbqsn5Rwg+WwF9kcMiTYRHLq Q6vw== 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 t2si1588252plz.344.2018.12.13.06.11.40; Thu, 13 Dec 2018 06:12:12 -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 S1728678AbeLMOKF (ORCPT + 99 others); Thu, 13 Dec 2018 09:10:05 -0500 Received: from www.osadl.org ([62.245.132.105]:39632 "EHLO www.osadl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727968AbeLMOKE (ORCPT ); Thu, 13 Dec 2018 09:10:04 -0500 Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59]) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id wBDE9Cw6015727; Thu, 13 Dec 2018 15:09:12 +0100 From: Nicholas Mc Guire To: Josh Poimboeuf Cc: Jessica Yu , Jiri Kosina , Miroslav Benes , Petr Mladek , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Nicholas Mc Guire Subject: [PATCH 1/2 V2] livepatch: handle kzalloc failure properly Date: Thu, 13 Dec 2018 15:05:55 +0100 Message-Id: <1544709956-16701-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 X-Spam-Status: No, score=-1.9 required=6.0 tests=BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on www.osadl.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kzalloc() return should always be checked - notably in example code where this may be seen as reference. On failure of allocation livepatch_fix1_dummy_alloc() should return NULL. Signed-off-by: Nicholas Mc Guire --- Problem was located with an experimental coccinelle script V2: ...and since it is reference code the fix should be correct as well... thanks to Petr Mladek for catching the missing kfree(). Patch was compile tested with: x86_64_defconfig + FTRACE=y FUNCTION_TRACER=y, EXPERT=y, LATENCYTOP=y, SAMPLES=y, SAMPLE_LIVEPATCH=y (with some unrelated sparse warnings on symbols not being static) Patch is against 4.20-rc6 (localversion-next is next-20181213) samples/livepatch/livepatch-shadow-fix1.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/samples/livepatch/livepatch-shadow-fix1.c b/samples/livepatch/livepatch-shadow-fix1.c index 49b1355..e8f1bd6 100644 --- a/samples/livepatch/livepatch-shadow-fix1.c +++ b/samples/livepatch/livepatch-shadow-fix1.c @@ -89,6 +89,11 @@ struct dummy *livepatch_fix1_dummy_alloc(void) * pointer to handle resource release. */ leak = kzalloc(sizeof(int), GFP_KERNEL); + if (!leak) { + kfree(d); + return NULL; + } + klp_shadow_alloc(d, SV_LEAK, sizeof(leak), GFP_KERNEL, shadow_leak_ctor, leak); -- 2.1.4