From owner-p4-projects@FreeBSD.ORG Tue Dec 5 04:51:13 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A531416A492; Tue, 5 Dec 2006 04:51:13 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7678516A47C for ; Tue, 5 Dec 2006 04:51:13 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.FreeBSD.org (Postfix) with ESMTP id 52A1E43C9D for ; Tue, 5 Dec 2006 04:50:36 +0000 (GMT) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id kB54pDnu059286 for ; Tue, 5 Dec 2006 04:51:13 GMT (envelope-from sam@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id kB54pCsx059266 for perforce@freebsd.org; Tue, 5 Dec 2006 04:51:12 GMT (envelope-from sam@freebsd.org) Date: Tue, 5 Dec 2006 04:51:12 GMT Message-Id: <200612050451.kB54pCsx059266@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to sam@freebsd.org using -f From: Sam Leffler To: Perforce Change Reviews Cc: Subject: PERFORCE change 111109 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Dec 2006 04:51:13 -0000 http://perforce.freebsd.org/chv.cgi?CH=111109 Change 111109 by sam@sam_ebb on 2006/12/05 04:51:11 o operations submitted through /dev/crypto are not supposed to use a s/w driver; we must explicitly check this for symmetric operations for the new ioctl that allows applications to specify a particular device/driver o fix comment for asym op case to explain the equivalent check is done in the core code NB: returning EINVAL for these cases isn't really helpful Affected files ... .. //depot/projects/crypto/sys/opencrypto/cryptodev.c#5 edit Differences ... ==== //depot/projects/crypto/sys/opencrypto/cryptodev.c#5 (text+ko) ==== @@ -129,6 +129,22 @@ return (EIO); } +/* + * Check a crypto identifier to see if it requested + * a software device/driver. This can be done either + * by device name/class or through search constraints. + */ +static int +checkforsoftware(int crid) +{ + if (crid & CRYPTOCAP_F_SOFTWARE) + return EINVAL; /* XXX */ + if ((crid & CRYPTOCAP_F_HARDWARE) == 0 && + (crypto_getcaps(crid) & CRYPTOCAP_F_HARDWARE) == 0) + return EINVAL; /* XXX */ + return 0; +} + /* ARGSUSED */ static int cryptof_ioctl( @@ -149,7 +165,7 @@ struct crypt_kop *kop; u_int64_t sid; u_int32_t ses; - int error = 0; + int error = 0, crid; /* * XXX: Not sure Giant is needed, but better safe than sorry @@ -267,9 +283,14 @@ } /* NB: CIOGSESSION2 has the crid */ - error = crypto_newsession(&sid, (txform ? &crie : &cria), - cmd == CIOCGSESSION2 ? - SES2(sop)->crid : CRYPTOCAP_F_HARDWARE); + if (cmd == CIOCGSESSION2) { + crid = SES2(sop)->crid; + error = checkforsoftware(crid); + if (error) + goto bail; + } else + crid = CRYPTOCAP_F_HARDWARE; + error = crypto_newsession(&sid, (txform ? &crie : &cria), crid); if (error) goto bail; @@ -320,7 +341,7 @@ return (EPERM); /* XXX compat? */ kop = (struct crypt_kop *)data; if (cmd == CIOCKEY) { - /* for backwards compatibility */ + /* NB: crypto core enforces s/w driver use */ kop->crk_crid = CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE; }