From patchwork Tue Jun 12 15:46:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 928397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 414vQC2V5Yz9s0w for ; Wed, 13 Jun 2018 01:46:59 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B1AEC1B9976 for ; Tue, 12 Jun 2018 17:46:56 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id D20DB1B9928 for ; Tue, 12 Jun 2018 17:46:51 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 8CF2D60076D for ; Tue, 12 Jun 2018 17:46:50 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D307EAF88 for ; Tue, 12 Jun 2018 15:46:49 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Tue, 12 Jun 2018 17:46:23 +0200 Message-Id: <20180612154631.435-2-chrubis@suse.cz> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180612154631.435-1-chrubis@suse.cz> References: <20180612154631.435-1-chrubis@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Subject: [LTP] [RFC PATCH 1/9] tst_safe_sysv_ipc: Make safe_shmctl() and safe_msgctl() safer X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" We recently had a regression in Sys V IPC when IPC_STAT returned non-zero integer on success wrongly, which wasn't caught by LTP test but breaks software in the wild. This commit changes safe_shmctl() and safe_msgctl() to check the return value with != 0 for IPC_STAT, IPC_SET and IPC_RMID and with == -1 otherwise. Signed-off-by: Cyril Hrubis Reviewed-by: Petr Vorel --- lib/tst_safe_sysv_ipc.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/lib/tst_safe_sysv_ipc.c b/lib/tst_safe_sysv_ipc.c index ff53a2420..86f2d934b 100644 --- a/lib/tst_safe_sysv_ipc.c +++ b/lib/tst_safe_sysv_ipc.c @@ -23,6 +23,24 @@ #include "tst_test.h" #include "tst_safe_sysv_ipc.h" +/* + * The IPC_STAT, IPC_SET and IPC_RMID can return either 0 or -1. + * + * Linux specific cmds either returns -1 on failure or positive integer + * either index into an kernel array or shared primitive indentifier. + */ +static int ret_check(int cmd, int ret) +{ + switch (cmd) { + case IPC_STAT: + case IPC_SET: + case IPC_RMID: + return ret != 0; + default: + return ret == -1; + } +} + int safe_msgget(const char *file, const int lineno, key_t key, int msgflg) { int rval; @@ -72,11 +90,13 @@ int safe_msgctl(const char *file, const int lineno, int msqid, int cmd, int rval; rval = msgctl(msqid, cmd, buf); - if (rval == -1) { - tst_brk(TBROK | TERRNO, "%s:%d: msgctl(%i, %i, %p) failed", - file, lineno, msqid, cmd, buf); + if (ret_check(cmd, rval)) { + tst_brk(TBROK | TERRNO, + "%s:%d: msgctl(%i, %i, %p) = %i failed", + file, lineno, msqid, cmd, buf, rval); } + return rval; } @@ -127,9 +147,10 @@ int safe_shmctl(const char *file, const int lineno, int shmid, int cmd, int rval; rval = shmctl(shmid, cmd, buf); - if (rval == -1) { - tst_brk(TBROK | TERRNO, "%s:%d: shmctl(%i, %i, %p) failed", - file, lineno, shmid, cmd, buf); + if (ret_check(cmd, rval)) { + tst_brk(TBROK | TERRNO, + "%s:%d: shmctl(%i, %i, %p) = %i failed", + file, lineno, shmid, cmd, buf, rval); } return rval;